<code><?php $array = array( 0 => array( '1a' => '', '3a' => '', '6a' => array( '6a1' => '', '6a2' => '', '6a3' => array( '6a31' => '', '6a33' => '', '6a34' => '1', ), ), ), 1 => array( '3b' => '', '4b' => array( '4b1' => '', '4b2' => '', ), '6b' => '', ) ); function search_val($key, $arr) { $v = ''; foreach ($arr as $ks => $vs) { if($ks != $key && is_array($vs)) { search_val($key, $vs); }else if($ks != $key && is_string($vs)) { continue; }else if($ks == $key) { $v = $vs; break; } } return $v; //var_dump($v);exit; //这里是有值的 为1 //echo $v; //测试这样可以直接输出 } $va = search_val('6a34', $array); var_dump($va); //$va始终为空 </code>
這個方法的意思就是給一下標$key
取出對應val
的值,我在方法最後return $v
,然後我把這個return
的結果賦給一個值$va
,這個值