Home  >  Article  >  Backend Development  >  PHP determines whether it is the last one in the array

PHP determines whether it is the last one in the array

(*-*)浩
(*-*)浩Original
2019-09-21 10:57:075502browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn