fork(3) download
  1. <?php
  2.  
  3. $array = [
  4. 'one' => 'a',
  5. 'two' => [
  6. 'default' => 'b',
  7. 'three' => [
  8. 'default' => 'c',
  9. 'four' => 'd'
  10. ],
  11. ],
  12. ];
  13. $p = ['two', 'three', 'default'];
  14.  
  15. function getElementByPass($arr, $pass) {
  16. $result = $arr;
  17. foreach($pass as $index) {
  18. $result = $result[$index];
  19. }
  20. return $result;
  21. }
  22.  
  23. print_r(getElementByPass($array, $p));
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
c