<?php $arr1 = Array( Array ( 'C1', 'C1', 'C1', 'AC', 'AC' ) ); $arr2 = Array( Array( 'C1_complete', 'C1_29-95', 'C1_49-95', 'AC_complete', 'AC_29-95' ) ); $data = array_combine(array_values($arr1[0]),array_fill(0,count($arr1[0]),[])); array_walk($arr2[0],function($value) use (&$data){ if(isset($data[explode("_",$value)[0]])) $data[explode("_",$value)[0]][] = $value; }); $data = [$data]; // since you want it inside another array. print_r($data);
You have javascript disabled. You will not be able to edit any code.