Are PHP Associative Arrays ordered?

前端 未结 4 1553
走了就别回头了
走了就别回头了 2020-11-30 11:52

I come from python background and the python datatype which is similar (a dictionary) is an unordered set of key value pairs.

I am wondering if PHP

4条回答
  •  时光说笑
    2020-11-30 12:54

    The array is ordered but that does not mean the keys are sorted, it means that they are in a given order. Where the precise order is not specified, but it appears to be the order in wich you introduced the key-value pairs in it.

    To understand it, think what would it mean to not be ordered? Well think to a relation in a relational database. A relation is not intrinsically ordered: when you access it with a query the database, unless you provide an order clause, can return the same data in any order. Even if the data was not modified the same data can be returned in different order.

提交回复
热议问题