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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:09:26
Original
919 people have browsed it

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...
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template