/** * 多维数组查询 * @param array $searchArr 需要查询的值 * @param array $data 需要查询的数组 * @return array 查询值所在数组 */ function searchArr(array $searchArr, array $data) { $str = json_encode($data); $r = array(); foreach ($searchArr as $key => $val) { $val = json_encode($val); $val = str_replace("\\", "\\\\", $val); $pattern = "/{[^{]*?\"{$key}\":{$val}[^}]*?}/"; preg_match($pattern, $str, $regs); if(!empty($regs)){ $r[] = json_decode($regs[0], true); } } return $r; } // 使用 $data = array( array( 'age' => 12, 'name' => '小刚', ), array( 'age' => 14, 'name' => '小红', ), array( 'age' => 33, 'name' => '小明', ), array( 'age' => 22, 'name' => '小花', ), ); $r = searchArr(array('name'=>'小花'), $data); print_r($r); // result Array ( [0] => Array ( [age] => 22 [name] => 小花 ) )