$array =array (1,2,3,4,5);
Echo $array [Count ($array) -1];//computes the length of the array, and then gets the last element of the array, if the last element in the array contains a non-numeric key name, the result may not match the expected
Applies to arrays with key names as numbers
Echo ' <br> ';
Echo End ($array);//The inner pointer of the array points to the last cell, for all arrays
Summary of three methods
<?PHP
$array
=
array
(1,2,4,6,8);
echo
end
(
$array
);
?>
<?PHP
$array
=
array
(1,2,4,6,8);
echo
array_pop
(
$array
);
?>
<?PHP
$array
=
array
(1,2,4,6,8);
$k
=
array_slice
(
$array
,-1,1);
print_r(
$k
);
//结果是一维数组
?>
The second method has a disadvantage, the Array_pop () function will be the last number of the original data "out", that is, the meaning of shearing, the original data will no longer have the last value
PHP array gets the last value