Page 1 of 1

array_values and array_keys

Posted: Sun Mar 05, 2006 7:34 am
by duk
i have a array like this:

Code: Select all

<?

$array = array (
 
    '1' => 'value1',
    '2' => 'value2'
);

?>
if i want to echo the value2, im doing this

Code: Select all

$var = array_values($array);
echo $var[1];


its make me a real bit confuse how can i do a echo directly without first put the array in $var ??

Posted: Sun Mar 05, 2006 10:08 am
by feyd

Code: Select all

echo $array['2'];
:?

Posted: Sun Mar 05, 2006 4:31 pm
by duk
lol i was realy confuse... thanks, i didn't know that php ignores the keys :)

Posted: Sun Mar 05, 2006 5:57 pm
by s.dot
you would be right with $array[1] to get the second value, except you renamed the keys starting with 1.. arrays start with 0