Re: How to test that an array is 'indexed' vs 'associative'



..oO(Daniel Klein)

On Sat, 31 May 2008 07:01:07 -0700 (PDT), jpedrobarbosa@xxxxxxxxx wrote:

my opinion is dont check it. just retreve the values with
"array_values"

I wish it was that easy but associative arrays are like 'hash tables' so the
values will not be in the proper order.

Even "numeric" arrays are just a hash table. There's no built-in order
of array elements. By default all elements are stored and retrieved in
the order in which they are inserted:

$foo = array(2 => 'foo', 1 => 'bar');
var_dump($foo);

If you want a "correct" order, you always have to use one of the various
array sorting functions.

Micha
.



Relevant Pages