Is the order of an associative array guaranteed in PHP?

前端 未结 4 392
一整个雨季
一整个雨季 2021-01-11 16:33

When I perform a foreach loop over an associatve array in php, the order in which it is performed is the order in which it is defined.

For example:

$         


        
4条回答
  •  醉梦人生
    2021-01-11 17:00

    Because arrays are always ordered, and the easiest and fastest way to iterate the array is just going from the first element to the last one (so there is no good reason to change the behavior for foreach()), you can be reasonably sure that this behavior will not change.

提交回复
热议问题