3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $select = [ 'foo', 'bar', [ 'size' => 128, 'type' => 'png' ], 'baz', 'qux' ]; function convert($in) { $out = []; for ($i = 0, $m = count($in); $i < $m; $i++) { $current = $in[$i]; $next = $in[$i + 1] ?? null; if (!is_string($current)) { throw new \Exception('Malformed field list.'); } if (is_array($next)) { $out[$current] = $next; $i++; } else { $out[$current] = true; } } return $out; } var_dump(convert($select));
based on VJPRT
Output for hhvm-3.18.4 - 3.21.0, 7.0.0 - 7.2.6
array(4) { ["foo"]=> bool(true) ["bar"]=> array(2) { ["size"]=> int(128) ["type"]=> string(3) "png" } ["baz"]=> bool(true) ["qux"]=> bool(true) }
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected '?' in /in/a1094 on line 16
Process exited with code 255.