<?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);
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`