慕桂英4014372
首先要指责一下,print_r的输出贴出来,怎么还原为数组代码,demo都写不了,要死啦。$arr=['a','b','hello'=>'原罪'];var_export($arr);//返回值:可以直接还原为代码array(0=>'a',1=>'b','hello'=>'原罪',);这个用reduce比较合适$result=array_reduce($arr,function($carry,$item){$extraProperties=['goods_stock','curr_price','goods_weight'];//先计算下标数量,提高效率$lengths=[];foreach($extraPropertiesas$property){$lengths[$property]=count($item[$property])-1;}//开始收集foreach($item['model_sub_name']as$index=>$subName){$sub=['model_name'=>$item['model_name'],'model_sub_name'=>$subName,];foreach($extraPropertiesas$property){$propertyIndex=min($index,$lengths[$property]);$sub[$property]=$item[$property][$propertyIndex];}$carry[]=$sub;}return$carry;},[]);其中$propertyIndex那边默认使用最后一个元素,应该可以满足你提的需求。你可以根据实际需求