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
欄位相同的組合在一起,並在前台輸出,類似電商網站的訂單合并,線上等
回複內容:
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; }
結果是一個三維數組