<?php $arr = array( array( 'foo' => 1, 'bar' => 2, 'thing' => 'apple' ), array( 'foo' => 1, 'bar' => 2, 'thing' => 'orange' ), array( 'foo' => 2, 'bar' => 2, 'thing' => 'apple' ), ); $newArr = $keys = array(); foreach ($arr as $row) { if (isset($keys[$row['foo']][$row['bar']])) { $newArr[$keys[$row['foo']][$row['bar']]]['thing'][] = $row['thing']; } else { $keys[$row['foo']][$row['bar']] = array_push($newArr, $row) - 1; $newArr[$keys[$row['foo']][$row['bar']]]['thing'] = array($row['thing']); } } unset($keys); print_r($newArr);
You have javascript disabled. You will not be able to edit any code.