3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = [['ID' => 1, 'Name' => 'My Name', 'GroupLocations' => [['GroupId' => 111, 'LocationId' => 222, 'Location' => ['Name' => 'MyLocation', 'Street1' => '555 Somewhere Lane']]]]]; $results = []; // the container for the search result(s) $key = 'Name'; // the key we are looking for findKey($arr, $key, $results); // invoke the search function /* NEW */ $count = count($results); for($i = 0; $i < $count; $i++) { $myVar = 'value' . $i; // set your base variable name $$myVar = $results[$i][$key]; // assign found value to new variable echo 'created variable: ' . '$value' . $i . ' - value : ' . $$myVar . "\n"; } echo $value0 ? $value0 : 'n/a'; echo $value1 ? $value1 : 'n/a'; // etc. /* END NEW */ /** * @param array $arr the multidimensional array we are searching * @param string $key the key we are looking for * @param $results passed by reference - in case the key is found, this array 'stores' the corresponding key-value pair. */ function findKey($arr = [], $key = '', &$results = []) { foreach ($arr as $key0 => $value0) { if ($key0 == $key && !is_array($value0)) { $results[][$key] = $value0; } if (is_array($value0)) { findKey($value0, $key, $results); } } return false; }
Output for rfc.property-hooks, git.master, git.master_jit
created variable: $value0 - value : My Name created variable: $value1 - value : MyLocation My NameMyLocation

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:
41.99 ms | 1431 KiB | 4 Q