$products = array(); $kk = 0; foreach ($products as $key => $value) { $Datas[‘datas‘][$kk][‘storeinfo‘][‘supplier_id‘] = $value[‘store_id‘]; $Datas[‘datas‘][$kk][‘storeinfo‘][‘supplier_name‘] = $value[‘supplier_name‘]; $k = 0; foreach ($products as $keyt => $valuet) { if($valuet[‘supplier_id‘] == $value[‘supplier_id‘]){ $Datas[‘datas‘][$kk][‘products‘][$k] = $valuet; $k ++; unset($products[$keyt]); } } //优化方式 复制一个数组循环两个不同名称的数组unset外层数组 if($k == 0){ unset($Datas[‘datas‘][$kk]); $kk --; } $kk ++; }