3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<? $arData = array( 0 => '5', 1 => '26', 2 => '6', 3 => '27' ); $arResult = array(); foreach ($arData as $key => $arValue) { $arResult[intval($key/2)][key($arValue)] = $arValue[key($arValue)]; } print_r($arResult); ?>
based on fePG0
Output for 5.4.34 - 7.1.0
Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Notice: String offset cast occurred in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Notice: String offset cast occurred in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Notice: String offset cast occurred in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Warning: key() expects parameter 1 to be array, string given in /in/s4048 on line 10 Notice: String offset cast occurred in /in/s4048 on line 10 Array ( [0] => Array ( [] => 2 ) [1] => Array ( [] => 2 ) )
Output for 4.3.0 - 5.4.32
<? $arData = array( 0 => '5', 1 => '26', 2 => '6', 3 => '27' ); $arResult = array(); foreach ($arData as $key => $arValue) { $arResult[intval($key/2)][key($arValue)] = $arValue[key($arValue)]; } print_r($arResult); ?>