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"]; $cats = []; $ids = []; foreach ($strings as $key=>$string) { $temps = explode(';', $string); foreach ($temps as $temp) { $tempnest = explode(':', $temp); if ($tempnest[0] === "cat") { $cats = array_merge(explode(',', $tempnest[1]), $cats); } if ($tempnest[0] === "id") { $ids = array_merge(explode(',', $tempnest[1]), $ids); } } } print_r(array_unique($cats)); print_r(array_unique($ids));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => drinks [1] => foods [3] => electric-products [4] => others ) Array ( [0] => 4 [1] => 9 [2] => 13 )

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