Hi I have an array which contains some key - value pairs I am wondering how can I get the first key in that array(just the first one)?
please help Thanks
If the array looks like this:
$array = array( 1 => "2", 2 => "3" );
or
$array['1'] = "2"; $array['2'] = "3";
then you can just do like this:
echo $array['1']; or echo $array['2'];
If the array looks something like this:
$array = array(1,2,3,4);
echo $array[0];
This will print 1, which is the first one in the array!
Does php guarantee the original order of an associative array will be maintained? I don't see anything in the docs either way. I know Perl explicitly said you could not assume any order in an associative array.
I suppose another way to code it would be to use foreach and escape from the loop at the end of the first iteration.
Found the answer. According to this reference anyway, the first-in/first-out order is guaranteed:
http://www.faqts.com/knowledge_base/view.phtml/aid/368/fid/17
ok
reset($array); list( $key, $value ) = each( $array );