怎样才能删除数组的最后一个元素?_PHP
程序员文章站
2022-06-17 18:08:02
...
用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
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