3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $blah= array(array('a'=> array('name' => 'test', 'alias' => 'testa'), 'b' => array('name' => 'test2', 'alias' => 'blah'))); $blank = array(); function _test(&$test, &$blank) { foreach ($test as $key => $value) { if (is_array($value) === false) continue; if (isset($value['alias']) === true) { var_dump('here'); $clonedArray = array(); $clonedArray = array_merge($clonedArray, $test); unset($clonedArray[$key]['alias']); $blank[$value['alias']] = $clonedArray; } if (isset($value['isalias']) === true) { $test[$key] = $blank[$value['name']]; } if (is_array($value) === true){ _test($test[$key], $blank); } } } _test($blah, $blank); var_dump($blah);
based on Tkqqn
Output for 5.3.22 - 5.6.28, 7.0.20 - 7.2.0
string(4) "here" string(4) "here" array(1) { [0]=> array(2) { ["a"]=> array(2) { ["name"]=> string(4) "test" ["alias"]=> string(5) "testa" } ["b"]=> array(2) { ["name"]=> string(5) "test2" ["alias"]=> string(4) "blah" } } }
Output for 7.0.0 - 7.0.6
string(4) "here" string(4) "here" array(1) { [0]=> array(2) { ["a"]=> &array(2) { ["name"]=> string(4) "test" ["alias"]=> string(5) "testa" } ["b"]=> array(2) { ["name"]=> string(5) "test2" ["alias"]=> string(4) "blah" } } }