3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $oldArray = range('a','e'); $newArray = array(); $len = count($oldArray); for($i = 0; $i < count($oldArray); $i+=2){ $key = $oldArray[$i]; $val = $i+1 < $len ? $oldArray[$i+1] : ''; $newArray[$key] = $val; } var_dump( $newArray);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(3) { ["a"]=> string(1) "b" ["c"]=> string(1) "d" ["e"]=> string(0) "" }