<?php header("Content-type:text/html;charset=utf-8"); $arr = array( ‘0‘=>array( ‘name‘=>‘热菜‘, ‘in‘=>‘in1‘, ‘on‘=>‘on2‘ ), ‘1‘=>array( ‘name‘=>‘热菜‘, ‘in‘=>‘in2‘, ‘on‘=>‘on2‘ ), ‘2‘=>array( ‘name‘=>‘热菜‘, ‘in‘=>‘in3‘, ‘on‘=>‘on3‘ ), ‘3‘=>array( ‘name‘=>‘凉菜‘, ‘in‘=>‘in4‘, ‘on‘=>‘on4‘ ), ); $new_name = array(); $data = array(); foreach ($arr as $key => $value) { if($value[‘name‘]){ $new_name[] = $value[‘name‘]; } } $res = array_unique($new_name); foreach ($res as $k => $v) { foreach ($arr as $kk => $vv) { if($v == $vv[‘name‘]){ $data[$k][‘name‘] = $v; $data[$k][‘data‘][] = $arr[$kk]; } } } print_r($data);
原数组是:
合并后的数组是:
时间: 2024-10-15 23:44:38