last index of array php code example
Example 1: get key of last element php
$key = array_key_last($data);
end($data);
$key = key($data);
Example 2: 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;
?>
Example 3: php index of last element in array
<?php
$source_array = [
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
];
echo "Last index: " . array_key_last($source_array);
?>
Example 4: php last item of array
echo end(['Gon', 'Killua', 'Hisoka'])