Php 从多维数组中获取值

Php 从多维数组中获取值,php,json,multidimensional-array,Php,Json,Multidimensional Array,我有一个脚本,可以创建以下格式的数组 $named_array["vehicles"][0]['vehicle'] = "i100-1 " ; $named_array["vehicles"][1]['vehicle'] = "i100-2 " ; $named_array["vehicles"][2]['vehicle'] = "i100-46 " ; 我想在脚本后面做的是从$named_数组中获取索引值[0-1-2等] 但是我只有这个值(i100-1等)作为一个查询选项,

我有一个脚本,可以创建以下格式的数组

  $named_array["vehicles"][0]['vehicle'] = "i100-1 "  ;
  $named_array["vehicles"][1]['vehicle'] = "i100-2 "  ;
  $named_array["vehicles"][2]['vehicle'] = "i100-46 "  ;
我想在脚本后面做的是从$named_数组中获取索引值[0-1-2等] 但是我只有这个值(i100-1等)作为一个查询选项,这样我以后可以修改它。我想要实现的是,
$named_array
的索引值是多少,其中值是i100-2

最后输出到json

我希望这是有意义的!需要帮忙吗

函数复合体索引($named\u数组,$val){
function complex_index_of($named_array, $val){
    for($i=0, $n=count($named_array['vehicles']); $i<$n; $i++){
        if ($named_array['vehicles'][$i]['vehicle'] == $val)
            return $i;
    }
    return -1;
}


echo complex_index_of($named_array, 'i100-2 ');
// output: 1
对于($i=0,$n=count($named_array['vehicles']);$i
function complex_index_of($named_array,$val){
对于($i=0,$n=count($named_array['vehicles']);$i尝试类似的方法(如果需要多次创建函数,可以创建函数)

尝试类似的方法(如果需要多次创建函数,可以创建一个函数)


我真的不明白你想要的结果是什么。我也不明白为什么你需要在
车辆
数组中为
车辆
添加另一个维度。Prince我想要车辆数组,这就是为什么我真的不明白你想要的结果是什么。我也不明白为什么你需要为
车辆添加另一个维度le
车辆的数组中
。Prince我想要车辆的数组,这就是为什么
$needle = 'i100-1';
$vIndex = -1;
foreach ($named_array["vehicles"] as $index => $data) {
    if($data['vehicle'] == $needle) {
        $vIndex = $index;
        break;
    }
}