3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(-1); $db_results = array( array('cat' => 1, 'id' => 1), array('cat' => 1, 'id' => 2), array('cat' => 2, 'id' => 3), array('cat' => 2, 'id' => 4) ); $category_map = array(); foreach ( $db_results as $row ) { $category_map[ $row['cat'] ][] = $row; } print_r($category_map);
Output for 4.3.0 - 7.2.0
Array ( [1] => Array ( [0] => Array ( [cat] => 1 [id] => 1 ) [1] => Array ( [cat] => 1 [id] => 2 ) ) [2] => Array ( [0] => Array ( [cat] => 2 [id] => 3 ) [1] => Array ( [cat] => 2 [id] => 4 ) ) )