Php 当只有一条记录时,不循环地从数组中获取密钥

Php 当只有一条记录时,不循环地从数组中获取密钥,php,arrays,Php,Arrays,我想在不循环的情况下从上面的数组中获取21,有可能吗?我想对那些只有1条记录的数组执行此操作。显然,我将不得不为其他人使用循环 $array['2']['21'] = null; 我看了,但没有完成我的工作。试试这个: foreach ($array['2'] as $key => $value) { echo $key; //I know this does the job wondering if there is simple function } $arr_keys

我想在不循环的情况下从上面的数组中获取
21
,有可能吗?我想对那些只有1条记录的数组执行此操作。显然,我将不得不为其他人使用循环

$array['2']['21'] = null;
我看了,但没有完成我的工作。

试试这个:

foreach ($array['2'] as $key => $value)
{
   echo $key;
   //I know this does the job wondering if there is simple function
}
$arr_keys=array_keys($array['2']);
回声“;
打印($arr_键);

Ref:

如果您不能直接分配它,您可以直接获得它的值
echo$array['2']['21']
如果它只包含一条记录,index 21如何才能准确地得到他想要的,使用
array\u键($array['2'])[0]
解决了我的问题。谢谢。@BartFriederichs:不……它被称为数组解引用,只有在PHP5.5+中才支持@MadMax:如果它解决了您的问题,别忘了接受它,这可能会帮助一些人找到答案。
$arr_keys  = array_keys($array['2']);

echo "<pre>";
print_r($arr_keys);