返回数组的最后一个数字键(NOT值)? [英] return last numeric key (NOT value) of an array?

查看:118
本文介绍了返回数组的最后一个数字键(NOT值)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的数组:

I have an array like this:

array[0] = "hello0"
array[1] = "hello1"
array[2] = "hello2"

现在我想获取数组的最后一个键 2。我不能使用end(),因为它将返回值 hello2。

Now I want to get the last key '2' of the array. I cant use end() because that will return the value 'hello2'.

我应该使用什么函数?

推荐答案

如果键不是连续的(例如,如果您具有键1、5、7):

If the keys are not continuous (i.e. if you had keys 1, 5, 7, for example):

$highest_key = rsort(array_keys($myarray))[0];

如果它们是连续的,只需使用 count($ myarray)-1

If they are continuous, just use count($myarray)-1.

这篇关于返回数组的最后一个数字键(NOT值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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