Last active
October 26, 2015 06:19
-
-
Save pafnuty/6d231eea42563a95c5b8 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
<? | |
function findKey($arr, $key) { | |
return $arr[$key]; | |
} | |
function superFunction($arr, $path) { | |
if (is_array($arr)) { | |
$path_str = explode('.', $path); | |
foreach ($path_str as $key) { | |
$arr = findKey($arr, $key); | |
} | |
return $arr; | |
} | |
} | |
$arr = [ | |
'list' => [ | |
'first' => [ | |
'val1' => 'one', | |
'val2' => 'two', | |
], | |
'second' => [ | |
'val11' => 'one1', | |
'val21' => 'two2', | |
], | |
], | |
]; | |
echo superFunction($arr, 'list.first.val1'); // one | |
echo superFunction($arr, 'list.second.val21'); // two2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment