[ create a new paste ] login | about

Link: http://codepad.org/ifZytVBp    [ raw code | output | fork ]

PHP, pasted on Jun 15:
<?php
function findKey($array,  $keySearch){
	$return = '';
    foreach ($array as $key => $item) {
        if ($key == $keySearch) {
            $return = $item;
        }else{
            if (is_array($item) && findKey($item, $keySearch)) {
               $return = true;
            }
        }
    }

    return $return;
}

$fruits = array ( "frutas"  => array ( "a" => "laranja",
                                       "b" => "banana",
                                       "c" => "maçã",
                                     ),
                  "numeros" => array ( "1" => "Um",
                                       "2" => "Dois",
                                       "3" => "Tres",
                                       "4" => "Quatro",
                                       "5" => "Cinco",
                                       "6" => "Seis"
                                     ),
                );

print_r(findKey($fruits, "a"));
?>


Output:
1
1


Create a new paste based on this one


Comments: