Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created October 30, 2019 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kcko/ef26f6db7966a27654fe3116202af176 to your computer and use it in GitHub Desktop.
Save Kcko/ef26f6db7966a27654fe3116202af176 to your computer and use it in GitHub Desktop.
<?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