php get last array element
snippet in php

how to get last array element in php

user2526

<?php

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

$result = end($source_array);

echo "Last element: ".$result;

?>

php get last array element

user3343

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