Skip to content

Instantly share code, notes, and snippets.

@pafnuty
Last active October 26, 2015 06:19
Show Gist options
  • Save pafnuty/6d231eea42563a95c5b8 to your computer and use it in GitHub Desktop.
Save pafnuty/6d231eea42563a95c5b8 to your computer and use it in GitHub Desktop.
<?
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
@pafnuty
Copy link
Author

pafnuty commented Oct 26, 2015

Cпасибо!
Обновил.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment