PHP - 获得关联数组的数字索引 [英] php - get numeric index of associative array
本文介绍了PHP - 获得关联数组的数字索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了一个关联数组,我需要找到一个关键的数字位置。
我可以通过循环来找到它,但但有没有更好的方式建设成PHP?
$ a =阵列(
'蓝'=> '好',
'车'=> '快速',
'数'=> '没有'
); //回波(找一个$ ['车']数字索引); //输出:1
解决方案
回声array_search(车,array_keys($ A));
I got an associative array and I need to find the numeric position of a key. I could loop through to find it but but is there a better way build into php?
$a = array(
'blue' => 'nice',
'car' => 'fast',
'number' => 'none'
);
// echo (find numeric index of $a['car']); // output: 1
解决方案
echo array_search("car",array_keys($a));
这篇关于PHP - 获得关联数组的数字索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文