Is the order of an associative array guaranteed in PHP?

前端 未结 4 478
一整个雨季
一整个雨季 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:10

    Your questions seems like you came from programming in Perl where "arrays" are not guaranteed to be in the order you created them. But in PHP it has always been ordered and will always be, otherwise a lot of code will break.

提交回复
热议问题