如何在关联数组中搜索数组值和返回键

时间:2014-01-22 19:28:16

标签: php search

<?php Array (
[2] =>
 Array ( [0] => cheap [1] => computer [2] => three ) 
[6] =>
 Array ( [0] => laptop [1] => phone [2] => car )
 ) ?>

我正在寻找一段时间来搜索“便宜”并获得2.指针赞赏。

1 个答案:

答案 0 :(得分:1)

$arr = Array ( [2] => Array ( [0] => cheap [1] => computer [2] => three ) 
               [6] => Array ( [0] => laptop [1] => phone [2] => car ) )

foreach($arr as $key=>$value){
   if(in_array("cheap", $value)){
      echo $key;
   }

}