[KLUG Programming] PHP arrays vs. structures
Adam Tauno Williams
awilliam at whitemice.org
Sat Jul 17 14:53:41 EDT 2004
> I think all arrays are associative in PHP.
That bites.
> Your example isn't quite correct, but your question is valid.
> To illustrate:
> $colors = array('red', 'blue', 'green', 'yellow');
> while (list($key,$val)=each($colors)) {
> echo "key is $key: val is $val<br />\n";
> } // end while
> That above will show the same results as:
> > $colors = array([0] => 'red',
> > [1] => 'blue',
> > [2] => 'green',
> > [3] => 'yellow');
Ah, so all the arrays created in a non-associative (key'd) way get
implicit numeric keys.
This solves my problems since the structures I have to deal with never
use numeric keys, so if the first key is 0 then it is an array,
otherwise it must be a structure (keys are strings). So I'm just lucky
(for once!) in this case.
More information about the Programming
mailing list