News for hackers. Stuff that matters.
Re:Python dicts are now ordered by slim on Friday February 07, 2020 @01:53PM (#22269335)
So how can you access, say, the third element of your ordered map in PHP ?
Re:Python dicts are now ordered by skrebbel on Friday February 07, 2020 @01:59PM (#22269420)

    array_values($arr)[2];
Re:Python dicts are now ordered by svnpenn on Friday February 07, 2020 @02:01PM (#22269458)
I mean youd probably have to iterate. Either that or use a package with proper array support.
Re:Python dicts are now ordered by slim on Friday February 07, 2020 @02:04PM (#22269488)
That's messed up
Re:Python dicts are now ordered by mywittyname on Friday February 07, 2020 @02:13PM (#22269603)
In practice, it's almost never an issue. The standard lib has push/pop/shift/pad methods available.

So example, if you had numeric indices that you wanted to guarantee that index order is equal to insertion order, you'd create an array using $my_array = array_pad([], 20, null); If it's an array that you didn't create, the ksort(...) method will order the array for you as expected.

Edit: after reading through the documentation on array_pad, it looks like it will even correct key order in existing arrays. https://www.php.net/manual/en/function.array-pad.php#87735