Created
October 30, 2019 19:34
-
-
Save Kcko/ef26f6db7966a27654fe3116202af176 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$arr = [ | |
'name' => 'Php Master', | |
'subject' => 'Php', | |
'type' => 'Articles', | |
'items' => [ | |
'one' => 'Iteration', | |
'two' => 'Recursion', | |
'methods' => [ | |
'factorial' => 'Recursion', | |
'fibonacci' => 'Recursion', | |
], | |
], | |
'parent' => 'Sitepoint', | |
]; | |
echo find_in_arr('one', $arr, 'devka'); | |
print_r($arr); | |
function find_in_arr($key, &$arr, $replace) { | |
foreach ($arr as $k => &$v) { | |
if ($k == $key) { | |
$arr[$k] = $replace; | |
return $v; | |
} | |
if (is_array($v)) { | |
$result = find_in_arr($key, $v, $replace); | |
if ($result != false) { | |
return $result; | |
} | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment