- array_shift: documentation ( source)
<?php
function array_by_path($value, $path) {
if (empty($path)) {
return $value;
}
$curr = array_shift($path);
if (!isset($value[$curr])) { return null; }
elseif (is_array($value[$curr])) { return array_by_path($value[$curr]); }
return $value;
}
$test = array(
'wot' => array(
'mate' => 'hello'
)
);
echo array_by_path($test, ['wot', 'mate']);