Created
September 14, 2012 21:19
-
-
Save mikejholly/3724921 to your computer and use it in GitHub Desktop.
PHP Recursion Fun
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 | |
$a = array( | |
'foo' => array( | |
'bar' => array( | |
'baz' => 'foo', | |
'bar' => array( | |
'loo' => 'poo' | |
), | |
), | |
), | |
); | |
function _r(&$a, $key, $value) { | |
foreach ($a as $k => &$v) { | |
if ($k == $key && $value == $v) { | |
return $a; | |
} | |
if (is_array($v)) { | |
return _r($v, $key, $value); | |
} | |
} | |
return NULL; | |
} | |
$r = _r($a, 'loo', 'poo'); | |
var_dump($r); | |
$r['loo'] = 'goo'; | |
print_r($a); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment