How to group an array of associative arrays by key in PHP

$result = array();
foreach ($data as $element) {
    $result[$element['id']][] = $element;
}