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" ]; $result = ['id' => [], 'cat' => []]; foreach ($strings as $string) { foreach (explode(';', $string) as $segment) { [$key, $values] = explode(':', $segment, 2); array_push($result[$key], ...explode(',', $values)); } } var_export(array_unique($result['id'])); echo "\n---\n"; var_export(array_unique($result['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:
162.23 ms | 405 KiB | 5 Q