key = array_key_last ($input_array);
| Parameter | DESCRIPTION |
|---|---|
| $input_array | Required : Input array for which last key is to be returned. |
$input=array(1,2,3,4,5);
echo array_key_last($input);
Output is here
4
Note that the first key is 0 , so the last key in above code is 4
$input=array('One' =>'First','Two'=>'Second','Three'=>'Third','Fourth');
echo var_dump(array_key_last($input));
The output is here
int(0)
<?php
$input = array(10, 20, 30, 40);
echo array_key_last($input); // Output: 3
?>
<?php
$input = array('a' => 'Apple', 'b' => 'Banana', 'c' => 'Cherry');
echo array_key_last($input); // Output: 'c'
?>
<?php
$emptyArray = array();
echo array_key_last($emptyArray); // Output: NULL
?>
<?php
$input = array('first' => 100, 'second' => 200, 'third' => 300);
unset($input['third']);
echo array_key_last($input); // Output: 'second'
?>
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.