Home >Backend Development >PHP Tutorial >How to delete the last element of an array?_PHP Tutorial
Just use the array_pop function in PHP4. Function prototype:
mixed array_pop(array array)
For example:
$array = array('PHP','JSP ','ASP');
$count = count($array);
echo 'old:
';
for($i=0;$i<$count;$i++ ) echo $array[$i].'
';
array_pop($array);
$count = count($array);
echo 'new:
';
for($i=0;$i<$count;$i++) echo $array[$i].'
';
?>
Output result:
old :
PHP
JSP
ASP
new:
PHP
JSP