Jedgar Justin
0
Q:

get last element from array in php

<?php

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

$result = end($source_array);

echo "Last element: ".$result;

?>
10
echo end($array);
7
end($arr)
2
<?php 
  
// input array 
$arr = array('Ram', 'Shita', 'Geeta'); 
  
// end function print the last 
// element of the array. 
echo end($arr);  
  
?> 
0

<?php

$people = array("Peter", "Joe", "Glenn", "Cleveland");

echo current($people) . "<br>";

echo end($people); 

?>
 
0

New to Communities?

Join the community