Home >Backend Development >PHP Tutorial >2 ways to get the last value of an array in PHP, 2 ways for arrays_PHP Tutorial

2 ways to get the last value of an array in PHP, 2 ways for arrays_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:26897browse

2 ways to get the last value of an array in PHP, 2 ways for arrays

Copy code The code is as follows:

$array=array(1,2,3,4,5);
echo $array[count($array)-1];//Calculate the length of the array, and then get the last element of the array. If the last element in the array contains a non-numeric key name, the result may not be as expected
//Applicable to arrays with key names
echo '
';
echo end($array);//Point the internal pointer of the array to the last unit, applicable to all arrays

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/945711.htmlTechArticlePHP has two methods to get the last value of an array. The two types of array copy code are as follows: $array=array( 1,2,3,4,5); echo $array[count($array)-1];//Calculate the length of the array, and then get the maximum length of the array...
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