|
|
|
|
|
by pak
5369 days ago
|
|
Perl hashes don't preserve order. PHP's almost always do. i.e., the order you insert keys is the order in which you will receive them back when you iterate over the array. It's similar to a LinkedHashMap in Java. CS types might recoil at the mixture of behaviors that are baked into PHP's workhorse data structure, but most of them turn out to be quite useful. (And it makes it easier for the beginner programmer to decide what data structure to use: you have keyed data? a list of data? a set of values? doesn't matter, just use an array!) |
|
This is the point at which serious students of language design point out that, if you look at it from a certain angle, PHP doesn't have arrays built into the language. As it turns out, treating two distinctly different data structures with different semantics and performance characteristics as the same thing multiplies edge cases and bugs.