3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = <<<STR category1_subcat_1 category1_subcat_2 category1_subcat_3 category2_subcat_1 category2_subcat_2 category3_subcat_1 category3_subcat_3 STR; // Explode the string, with a newline as the delimiter $lines = explode("\n", $str); // Init the category array $cats = []; // iterate over the lines foreach($lines as $currentLine) { // Match category{DIGIT} using regular exp preg_match("/category[0-9]/", $currentLine, $match); // Remove the $match from the current line $currentLine = str_replace($match[0], "", $currentLine); // Push the element to the categories array, and also remove the // the underscores (_) $cats[$match[0]][] = str_replace("_", "", $currentLine); } var_dump($cats);
Output for git.master, git.master_jit, rfc.property-hooks
array(3) { ["category1"]=> array(3) { [0]=> string(7) "subcat1" [1]=> string(7) "subcat2" [2]=> string(7) "subcat3" } ["category2"]=> array(2) { [0]=> string(7) "subcat1" [1]=> string(7) "subcat2" } ["category3"]=> array(2) { [0]=> string(7) "subcat1" [1]=> string(7) "subcat3" } }

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:
167.97 ms | 406 KiB | 5 Q