Home > php教程 > php手册 > PHP获取数组最后一个值的2种方法

PHP获取数组最后一个值的2种方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:13:27
Original
1156 people have browsed it

这篇文章主要介绍了PHP获取数组最后一个值的2种方法,本文直接给出实现代码,代码中包含注释,需要的朋友可以参考下

复制代码 代码如下:


$array=array(1,2,3,4,5);   
echo $array[count($array)-1];//计算数组长度,然后获取数组最后一个元素,如果数组中最后一个元素含有非数字键名,结果可能跟预期不符合   
//适用于键名为数字的数组   
echo '
';   
echo end($array);//将数组的内部指针指向最后一个单元,,适用于所有数组   

Related labels:
php
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template