首页 > 重组数组,实现类似淘宝一样的合并订单

重组数组,实现类似淘宝一样的合并订单

array (
  '0' =>
    array (
      'id' => string '22',
      'title' => string '商品名称',
      'test' => string '123',
      )
  '1' =>
    array (
      'id' => string '23',
      'title' => string '商品名称',
      'test' => string '125',
      )
  '2' =>
    array (
      'id' => string '30',
      'title' => string '商品名称',
      'test' => string '123',
      )
)

类似上面的数组,需要把test字段相同的组合在一起,并在前台输出,类似电商网站的订单合并,在线等


其实很简单:

$arra =   array (
            '0' => array ('id' =>  '22', 'title' =>  '商品名称', 'test' =>  '123',),
  '1' => array ('id' =>  '23', 'title' =>  '商品名称', 'test' => '125',),
  '2' => array ('id' =>  '30', 'title' =>  '商品名称', 'test' =>  '123',));
        $result = array();
        foreach($arra as $key => $value){
            $result[$value['test']][] = $value;
        }

结果是一个三维数组

【热门文章】
【热门文章】