Hello Reader!
Getting last the key index of any array PHP can be done on several ways as follows:-
Lets consider an example array $MyArray
$MyArray = array(
'one' => firstelement,
'two' => secondelement,
'three' => lastelement,
);
end($MyArray);
Using this syntax your pointer will move to the last index on your array $MyArray.
$LastKey = key($MyArray);
Now you can take the last element of you array once get by you pointer above
Now you just need to print that value
echo "$LastKey";
Now this is much more easy syntex:-
echo $array[count($MyArray) - 1];
Here above we can directly get the to the last key by using count -1,and you will get the element on last key.
0 Comment(s)