Home >Backend Development >PHP Problem >PHP determines whether it is the last one in the array
current() function returns the value of the current element in the array.
Each array has an internal pointer pointing to its "current" element, initially pointing to the first element inserted into the array.
end() - Points the internal pointer to the last element in the array and outputs
next() - Points the internal pointer to the next element in the array An element, and output (recommended learning: PHP programming from entry to proficiency)
prev() - Point the internal pointer to the previous element in the array, and output
reset() - Point the internal pointer to the first element in the array, and output
each() - Return the key name and key value of the current element, and move the internal pointer forward
$tmp = array('a','b','c','d'); echo current($tmp)."\n"; echo end($tmp)."\n"; echo current($tmp)."\n"; reset($tmp); echo current($tmp)."\n";
For example:
<?PHP $array = array(1,2,4,6,8); echo end($array); ?> <?PHP $array = array(1,2,4,6,8); echo array_pop($array); ?> <?PHP $array = array(1,2,4,6,8); $k = array_slice($array,-1,1); print_r($k); //结果是一维数组 ?>
The above is the detailed content of PHP determines whether it is the last one in the array. For more information, please follow other related articles on the PHP Chinese website!