3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ "cat:others;id:4,9,13", "id:4,9,13;cat:electric-products", "id:4,9,13;cat:foods", "cat:drinks,foods" ]; $count = preg_match_all( '/(?:^|;)(id|cat):|\G(?!^),?([^,;]+)/', implode(';', $strings), $matches, PREG_UNMATCHED_AS_NULL ); $cat = []; $id = []; for ($i = 0; $i < $count; ++$i) { if ($matches[1][$i] !== null) { $arrayName = $matches[1][$i]; } else { ${$arrayName}[$matches[2][$i]] = $matches[2][$i]; } } var_export(array_values($id)); echo "\n---\n"; var_export(array_values($cat));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => '4', 1 => '9', 2 => '13', ) --- array ( 0 => 'others', 1 => 'electric-products', 2 => 'foods', 3 => 'drinks', )

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:
163.16 ms | 405 KiB | 5 Q