<?php
$array = [
'one' => 'a',
'two' => [
'default' => 'b',
'three' => [
'default' => 'c',
'four' => 'd'
],
],
];
$p = ['two', 'three', 'default'];
function getElementByPass($arr, $pass) {
$result = $arr;
foreach($pass as $index) {
$result = $result[$index];
}
return $result;
}
print_r(getElementByPass
($array, $p));
PD9waHAKCiRhcnJheSA9IFsKICAgICdvbmUnID0+ICdhJywKICAgICd0d28nID0+IFsKICAgICAgICAnZGVmYXVsdCcgPT4gJ2InLAogICAgICAgICAgICAndGhyZWUnID0+IFsKICAgICAgICAgICAgICAgICdkZWZhdWx0JyA9PiAnYycsIAogICAgICAgICAgICAgICAgJ2ZvdXInID0+ICdkJwogICAgICAgICAgICBdLAogICAgXSwKXTsKJHAgPSBbJ3R3bycsICd0aHJlZScsICdkZWZhdWx0J107CgpmdW5jdGlvbiBnZXRFbGVtZW50QnlQYXNzKCRhcnIsICRwYXNzKSB7CiAgICAgICAgJHJlc3VsdCA9ICRhcnI7CiAgICAgICAgZm9yZWFjaCgkcGFzcyBhcyAkaW5kZXgpIHsKICAgICAgICAgICAgJHJlc3VsdCA9ICRyZXN1bHRbJGluZGV4XTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICRyZXN1bHQ7CiAgICB9CiAgICAKcHJpbnRfcihnZXRFbGVtZW50QnlQYXNzKCRhcnJheSwgJHApKTs=