Return to Snippet

Revision: 64036
at June 29, 2013 17:13 by noganno


Initial Code
function find_in_arr($key, $arr) {
    foreach ($arr as $k=>$val) {
        if($k == $key) {
            return $val;
        }

        if(is_array($val)) {
            $result = find_in_arr($key, $val);
            if($result != false) {
                return $result;
            }
        }
    }
    return false;
}




$arr = array(
    'name' => 'Php Master',
    'subject' => 'Php',
    'type' => 'Articles',
    'items' => array(
        'one' => 'Iteration',
        'two' => 'Recursion',
        'methods' => array(
            'factorial' => 'Recursion',
            'fibonacci' => 'Recursion',
        ),
    ),
    'parent' => 'Sitepoint',
);

var_dump(find_in_arr('fibonacci', $arr));

Initial URL
http://phpmaster.com/understanding-recursion/

Initial Description
поиск значения в многомерном массиве

Initial Title
Рекурсия в php

Initial Tags
php

Initial Language
PHP