带有键值的PHP数组搜索

时间:2017-11-28 11:11:19

标签: php

我有以下数组:

<?php 
$a=array(
    "abc"=>array("red","white","orange"),
    "def"=>array("green","vilot","yellow"),
    "xyz"=>array("blue","dark","pure")
); 

echo array_search(array("dark"),$a);

?>

如何在数组列表中输出xyz。

1 个答案:

答案 0 :(得分:0)

请试试这个

function searchMultiArray($arrayVal,$val){
    foreach($arrayVal as $key => $suba){

        if (in_array($val, $suba)) {
         return $key;
     }

 }
}

$a = array("abc"=>array("red","white","orange"),"def"=>array("green","vilot","yellow"),"xyz"=>array("blue","dark","pure"));
echo $keyVal = searchMultiArray($a , "dark");