php - 获取关联数组的数字索引 [英] php - get numeric index of associative array

查看:77
本文介绍了php - 获取关联数组的数字索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关联数组,我需要找到一个键的数字位置.我可以手动遍历数组来找到它,但有没有更好的方法构建到 PHP 中?

I have an associative array and I need to find the numeric position of a key. I could loop through the array manually to find it, 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屋!

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