3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Search into a multi dimensional array to find arbitrary data * @param array $array The array to search * @param string ... Any number of array keys * @return mixed */ function deepArraySearch(array $array, ...$keys) { // If no more keys to use if(!$keys) { return $array; } $nextKey = array_shift($keys); // Nothing left to search if(!is_array($array[$nextKey])) { return $array[$nextKey]; } return deepArraySearch($array[$nextKey], ...$keys); } $arr = ['one' => ['two' => ['three' => 'data']]]; print_r(deepArraySearch($arr, 'one')); print_r(deepArraySearch($arr, 'one', 'two')); print_r(deepArraySearch($arr, 'one', 'two', 'three')); echo PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [two] => Array ( [three] => data ) ) Array ( [three] => data ) data

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.15 ms | 405 KiB | 5 Q