日期:2014-05-17 浏览次数:20449 次
$arr = array( array('goods_id'=>'1','sku_id'=>'001','zk'=>'0.5'), array('goods_id'=>'1','sku_id'=>'002','zk'=>'0.5'), array('goods_id'=>'1','sku_id'=>'006','zk'=>'0.5'), array('goods_id'=>'2','sku_id'=>'003','zk'=>'0.8'), array('goods_id'=>'2','sku_id'=>'004','zk'=>'0.8'), );
$_arr = array( '1' =>array( 'zk'=>'0.5', 'mx'=>array( array('sku_id'=>'001','zk'=>'0.5'), array('sku_id'=>'002','zk'=>'0.5'), array('sku_id'=>'006','zk'=>'0.5'), ), '2' =>array( 'zk'=>'0.8', 'mx'=>array( array('sku_id'=>'003','zk'=>'0.8'), array('sku_id'=>'004','zk'=>'0.8'), ), ) );
<?php $arr = array( array('goods_id'=>'1','sku_id'=>'001','zk'=>'0.5'), array('goods_id'=>'1','sku_id'=>'002','zk'=>'0.5'), array('goods_id'=>'1','sku_id'=>'006','zk'=>'0.5'), array('goods_id'=>'2','sku_id'=>'003','zk'=>'0.8'), array('goods_id'=>'2','sku_id'=>'004','zk'=>'0.8'), ); foreach($arr as $v){ $tmp[$v['zk']]['zk']=$v['zk']; $tmp[$v['zk']]['mx'][]=array_splice($v,1,2); } print_r(array_values($tmp));