3v4l.org

run code in 300+ PHP versions simultaneously
<?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));
Output for git.master, git.master_jit, rfc.property-hooks
array(4) { ["foo"]=> bool(true) ["bar"]=> array(2) { ["size"]=> int(128) ["type"]=> string(3) "png" } ["baz"]=> bool(true) ["qux"]=> bool(true) }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.85 ms | 401 KiB | 8 Q