Answers for "php get last array item"

PHP
17

how to get last array element in php

<?php

$source_array = ['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'];

$result = end($source_array);

echo "Last element: ".$result;

?>
Posted by: Guest on August-05-2020
0

php get second last element of array

$array = array(5,6,70,10,36,2);
echo $array[count($array) -2];
Posted by: Guest on May-20-2021

Browse Popular Code Answers by Language