开发者

How can I find the value of the first element in an associative array in PHP?

开发者 https://www.devze.com 2023-01-18 17:10 出处:网络
I have an array like this: $array = array( \'fruit1\' => \'apple\', \'frui开发者_如何学Pythont2\' => \'orange\',

I have an array like this:

$array = array(
    'fruit1' => 'apple',
    'frui开发者_如何学Pythont2' => '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;
    }
}


$firstValue = reset($array);

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

0

精彩评论

暂无评论...
验证码 换一张
取 消