fork download
  1. <?php
  2.  
  3. function get(array $array, $keys) {
  4. $val = $array;
  5. foreach (explode('/', $keys) as $part) {
  6. if (!isset($val[$part])) {
  7. return null;
  8. }
  9. $val = $val[$part];
  10. }
  11. return $val;
  12. }
  13.  
  14. $array['foo']['bar']['baz'] = 'something';
  15. var_dump($array);
  16. var_dump(get($array, 'foo/bar/baz'));
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
array(1) {
  ["foo"]=>
  array(1) {
    ["bar"]=>
    array(1) {
      ["baz"]=>
      string(9) "something"
    }
  }
}
string(9) "something"