Home > php教程 > php手册 > 怎样才能删除数组的最后一个元素?

怎样才能删除数组的最后一个元素?

WBOY
Release: 2016-06-13 10:13:36
Original
1307 people have browsed it

用PHP4中带的array_pop这个函数即可,函数原型:
mixed array_pop(array array)
举个例子:

$array = array('PHP','JSP','ASP');
$count = count($array);
echo 'old:
';
for($i=0;$i';
array_pop($array);
$count = count($array);
echo 'new:
';
for($i=0;$i';
?>
输出结果:
old:
PHP
JSP
ASP
new:
PHP
JSP

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