3v4l.org

run code in 300+ PHP versions simultaneously
<?php $category_input = array( 'cat_20', 'post-in-cat-20', 'post-in-cat-20', 'post-in-cat-20', 'cat_19', 'post-in-cat-19', 'post-in-cat-19', 'post-in-cat-19', 'post-in-cat-19', 'cat_2', 'post-in-cat-2', 'post-in-cat-2', 'post-in-cat-2' ); $out_arr = array(); foreach($category_input as $val){ $part = explode('_', $val); if(isset($part[0]) && $part[0] == 'cat'){ $out_arr[$val] = array(); $key = $val; }else{ $out_arr[$key][] = $val; } } print_r($out_arr);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [cat_20] => Array ( [0] => post-in-cat-20 [1] => post-in-cat-20 [2] => post-in-cat-20 ) [cat_19] => Array ( [0] => post-in-cat-19 [1] => post-in-cat-19 [2] => post-in-cat-19 [3] => post-in-cat-19 ) [cat_2] => Array ( [0] => post-in-cat-2 [1] => post-in-cat-2 [2] => post-in-cat-2 ) )

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:
48.57 ms | 2107 KiB | 4 Q