得到的最后一个元素的密钥以阵列 [英] Get key of the last element in an array

查看:72
本文介绍了得到的最后一个元素的密钥以阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

干草,我有一个包含了一组数组的数组,这里是一个例子。

 阵列(
    [0] =>阵列('名'=>'鲍勃'),
    [2] =>阵列('名'=>'嗵'),
    [3] =阵列('名'=>标记)

该如何获得数组中的最后一个项目,并返回它的键。

因此​​,在上面的例子中,将返回3。


解决方案

 端($数组);
回声关键($数组)

这应该返回的最后一个元素的关键。

Hay, i have an array which contains a set of arrays, here's an example.

array(
    [0]=>array('name'=>'bob'),
    [2]=>array('name'=>'tom'),
    [3]=array('name'=>'mark')
)

How would i get the last item in the array, and returns it's key.

So in the above example it would return 3.

解决方案

end($array);
echo key($array)

This should return the key of the last element.

这篇关于得到的最后一个元素的密钥以阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆