function recursivesearchkeybyval($array, $needle) { //$k = false; foreach($array $key => $val) { if( is_array($val) ) { $k = array_search($needle, $val); if( $k ) { #var_dump($k); //<-- string(8) "12345678" true return $k; //<-- bool(false) false ????????? } else { recursivesearchkeybyval($val, $needle); } } } return false; } $array = array( 'a'=>array(...), 'b'=>array( 'b1'=>array( '12345678'=>'abcdefgh' ), ...) ); var_dump( recursivesearchkeybyval($array, 'abcdefgh') ); i have recursive function , can't make return correct value... returns false.
heh, call function. when call function called again , again. when return value false, it's been deeper 1 execution.
you need that:
function recursivesearchkeybyval($array, $needle) { $k = false; foreach($array $key => $val) { if( is_array($val) ) { $k = array_search($needle, $val); if( $k ) { #var_dump($k); //<-- string(8) "12345678" true return $k; //<-- bool(false) false ????????? } else { $k = recursivesearchkeybyval($val, $needle); } } } return $k; }
Comments
Post a Comment