3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
45.83 ms | 402 KiB | 5 Q