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) { if(isset($mas[$itm['id']])) { $mas[$itn['p']][$itm['id']]['name'] = 'aaa'.$ind; $mas[$itn['p']][$itm['id']] = $mas[$itm['id']]; unset($mas[$itm['id']]); } else { $mas[$itm['p']][$itm['id']]['name'] = 'aaa'.$ind; } } print_r($mas);
Output for 5.0.4 - 5.6.22, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined variable: itn in /in/LcjPW on line 16 Notice: Undefined variable: itn in /in/LcjPW on line 17 Notice: Undefined variable: itn in /in/LcjPW on line 16 Notice: Undefined variable: itn in /in/LcjPW on line 17 Array ( [] => Array ( [3] => Array ( [4] => Array ( [name] => aaa0 ) [5] => Array ( [name] => aaa1 ) [6] => Array ( [name] => aaa2 ) ) [1] => Array ( [2] => Array ( [name] => aaa4 ) [7] => Array ( [name] => aaa5 ) ) ) )
Output for 4.3.0 - 5.0.3
Notice: Undefined variable: itn in /in/LcjPW on line 16 Notice: Undefined variable: itn in /in/LcjPW on line 17 Notice: Undefined variable: itn in /in/LcjPW on line 16 Notice: Undefined variable: itn in /in/LcjPW on line 17 Array ( [] => Array ( [3] => Array ( [4] => Array ( [name] => aaa0 ) [5] => Array ( [name] => aaa1 ) [6] => Array ( [name] => aaa2 ) ) [1] => Array ( [2] => Array ( [name] => aaa4 ) [7] => Array ( [name] => aaa5 ) ) ) )