3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $arr = array(); $arr[] = array('p' => 3, 'id' => 4); $arr[] = array('p' => 3, 'id' => 5); $arr[] = array('p' => 3, 'id' => 6); $arr[] = array('p' => 2, 'id' => 3); $arr[] = array('p' => 1, 'id' => 2); $arr[] = array('p' => 1, 'id' => 7); $arr[] = array('p' => 0, 'id' => 1); $mas = array(); foreach($arr as $ind => $itm) { $mas[$itm['p']][$itm['id']] = 'aaa'.$ind; } print_r($mas);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [3] => Array ( [4] => aaa0 [5] => aaa1 [6] => aaa2 ) [2] => Array ( [3] => aaa3 ) [1] => Array ( [2] => aaa4 [7] => aaa5 ) [0] => Array ( [1] => aaa6 ) )