From: Keith D. <ya...@ke...> - 2002-09-07 20:57:16
|
> On Sat, Sep 07, 2002 at 04:01:57PM -0400, Keith Devens wrote: > | > I have a question about PHP. It says that it is an "ordered map" but > | > all of the examples I've seen show an associative container. > | > | When you do a foreach(){}, or use each(), you get the elements back in > | the same order you put them in. > > By elements do you mean "values" or "pairs"? Well, whatever you ask for is given to you in order. So array_keys() and array_values() give you things that way. The loops will let you specify whether you want pairs or just values, so you can say foreach($arr as $key=>$val){}or just foreach($arr as $val) (I don't like the "as" syntax either). Similarly for while: while(list($key, $val) = each($arr){} or just while(list(,$val) = each($array){}. each() by itself actually gives you this: Array ( [1] => b [value] => b [0] => a [key] => a ) Which I never knew before. So list() looks at the numeric indices. |