3v4l.org

run code in 150+ 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 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.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 ) ) )