reset()和
end()这样做。
从手册:
07002: Returns the value of the first array element, or FALSE if the array is empty.
07003: Returns the value of the last element or FALSE for empty array.
例:
$array = array(24.0,24.1,24.2,24.3,24.4,24.5,24.6);
$first = reset($array);
$last = end($array);
var_dump($first, $last);
?>
哪些输出:
float(24)
float(24.6)
注意:这将重置您的数组指针,意思是如果您使用current()获取当前元素,或者您已经在数组的中间查找,则reset()和end()将重置数组指针(到开始和结束):
$array = array(30.0, 24.0, 24.1, 24.2, 24.3, 24.4, 24.5, 24.6, 12.0);
// reset — Set the internal pointer of an array to its first element
$first = reset($array);
var_dump($first); // float(30)
var_dump(current($array)); // float(30)
// end — Set the internal pointer of an array to its last element
$last = end($array);
var_dump($last); // float(12)
var_dump(current($array)); // float(12) - this is no longer 30 - now it's 12