http://qs1969.pair.com?node_id=784454


in reply to Difference between array and a hash? (Newbie concerns)

Basically every "array" in PHP is an array and a hash, glued together. All of the values are stored in the hash as key/value pairs, but there's an array stored along with it that gives an ordering to the keys. The thing is, most of the time you either need one behavior (in-order processing) or the other (random lookup), and not both. PHP is giving you the overhead of both at all times; Perl is requiring you to say which one you really want. In the case where you really do need both methods, it's not very hard to set up the necessary parallel data structure in your own code, but Tie::IxHash is another option.

Replies are listed 'Best First'.
Re^2: Difference between array and a hash? (Newbie concerns)
by Anonymous Monk on Jul 30, 2009 at 03:28 UTC
    In perl that used to be called pseudohash, but they were removed.
      Pseudohash goes the other way, though. Pseudohashes were arrays internally, with a hash glued on so that the items could be accessed by key. The "ordered hash" as provided by PHP or IxHash is a hash primarily, with an array glued on to provide an ordering.
        Those are implementation details, not really relevant to how you use either