3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $results = array ( array( 'body' => 'somevalue1', 'title' => 'somevalue1', 'type' => 'foo' ), array( 'body' => 'somevalue2', 'title' => 'somevalue2', 'type' => 'foo' ), array( 'body' => 'somevalue3', 'title' => 'somevalue3', 'type' => 'bar' ), array( 'body' => 'somevalue4', 'title' => 'somevalue4', 'type' => 'foobar' ), array( 'body' => 'somevalue5', 'title' => 'somevalue5', 'type' => 'foobar' ), array( 'body' => 'somevalue6', 'title' => 'somevalue6', 'type' => 'foobar' ), ); foreach($results as $a){ $output[$a['type']][]=array_slice($a,0,2); } var_export($output);
based on 5WFOM
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
array ( 'foo' => array ( 0 => array ( 'body' => 'somevalue1', 'title' => 'somevalue1', ), 1 => array ( 'body' => 'somevalue2', 'title' => 'somevalue2', ), ), 'bar' => array ( 0 => array ( 'body' => 'somevalue3', 'title' => 'somevalue3', ), ), 'foobar' => array ( 0 => array ( 'body' => 'somevalue4', 'title' => 'somevalue4', ), 1 => array ( 'body' => 'somevalue5', 'title' => 'somevalue5', ), 2 => array ( 'body' => 'somevalue6', 'title' => 'somevalue6', ), ), )