views:

42

answers:

1

I have an array like this:

$array = array(
    'fruit1' => 'apple',
    'fruit2' => 'orange',
    'fruit3' => 'grape',
);

Is there a function that'll grab 'apple' (the first key) from that array? Or do I have no choice but to do this?

function firstkey($array)
{
    for($array as $first)
    {
        return $first;
    }
}
+6  A: 

$firstValue = reset($array);

http://www.php.net/manual/en/function.reset.php

Thanks for the quick answer! (can't accept for 11 minutes)
Eric