Created
May 27, 2015 08:28
-
-
Save yadakhov/59f614c89f53cee5e0aa 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
$a = array('foo' => array('bar' => array('baz' => 1))); | |
function resolve(array $a, $path, $default = null) | |
{ | |
$current = $a; | |
$p = strtok($path, '.'); | |
while ($p !== false) { | |
if (!isset($current[$p])) { | |
return $default; | |
} | |
$current = $current[$p]; | |
$p = strtok('.'); | |
} | |
return $current; | |
} | |
var_dump(resolve($a, 'foo.bar')); | |
// array('baz' => 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment