Possible Duplicate:
How to get last key in an array?
I have an array
$arr=Array
(
[0] = Array
(
[groupid] = 1
[groupname] = Oxy
[members] = Array
(
[0] = Array
(
[id] = 9
[name] => Anith
)
[1] = Array
(
[id] = 12
[name] = sanjay
)
[3] =Array
(
[id] = 13
[name] = Sooraj K
)
)
) )
Here $arr[0]['members'][2]
is unsetted. I want to find the last index of $arr[0]['members']
here that is 3..how can i find this last index
$last = end($arr[0]['members']);
Do like :
<?php
$arr_keys = array_keys($arr[0]['members']);
$last_index = $arr_keys[count($arr_keys)-1];
?>
$last = max(array_keys($arr[0]['members']));
Of course, this means sorted array.
You can simply count the array, i.e
$count = count($arr[0]['members']);
This will give total number of index. Then to fetch it, you can go like
$last_array = $arr[0]['members'][$count-1];
I also suggest to also check that it is greater that 0 or not.
This will work for you.
end($arr[0]["members"]);
$key = key($arr[0]["members"]);
It will return you 3.