Two arrays are given, first:

$array = [ 'one' => 'a', 'two' => [ 'default' => 'b', 'three' => [ 'default' => 'c', 'four' => 'd' ], ], ]; 

second:

 $p = ['two', 'three', 'default']; 

It is necessary to obtain a value from the first array, the path to which is written in the second array. In this example, it is c .

    1 answer 1

     function getElementByPass($arr, $pass) { $result = $arr; foreach($pass as $index) { $result = $result[$index]; } return $result; } 

    Must work ( ideone )

    Ps. Wrap in Try \ catch so that there are no sudden errors when the path is not found.

    • Checked, works - Mr. Black