当一个数组被传递给 foreach 时,是否保证输出顺序与输入相同?我知道在某些语言中无法保证输出顺序,因为每个元素都是同时处理的.
When an array is passed to foreach is the output order guaranteed to be the same as the input? I know in some languages that the output order is not guaranteed since each element is processed at the same time.
例如,我将一个已排序的数组传递给 foreach 以写入文件.我想确保数组将在输出文件中排序.
For example, I'm passing a sorted array to foreach to write to a file. I want to be sure that the array will be sorted in the output file.
是的...无论你给 foreach 提供什么顺序,它都会以相同的顺序迭代.在您的情况下,array 将在输出文件中排序.
Yes ...whatever order you will give to foreach it will iterate in same orders. And in your case array will be sorted in the output file.
这篇关于foreach 是否保证在 php 中按数组顺序迭代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)