3v4l.org

run code in 300+ PHP versions simultaneously
<?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']])) { if($itm['p'] == 0) { $mas[$itm['id']]['elements'] = $mas[$itm['id']]; $mas[$itm['id']]['name'] = 'aaa'.$ind; }else{ $mas[$itm['p']][$itm['id']]['elements'] = $mas[$itm['id']]; unset($mas[$itm['id']]); $mas[$itm['p']][$itm['id']]['name'] = 'aaa'.$ind; } } } print_r($mas);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
41.65 ms | 401 KiB | 8 Q