3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array( 'one' => 'string1', 'two' => 'string2', 'three' => 'string3', 'four' => 'string4'); $aNewArray=array(); foreach($array as $key=>$value) { switch($key) { case 'one': $aNewArray[3]['one']=$value; break; case 'two': $aNewArray[2]['two']=$value; break; case 'three': $aNewArray[1]['three']=$value; break; case 'four': $aNewArray[1]['four']=$value; break; } } print_r($aNewArray);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [3] => Array ( [one] => string1 ) [2] => Array ( [two] => string2 ) [1] => Array ( [three] => string3 [four] => string4 ) )