3v4l.org

run code in 300+ PHP versions simultaneously
<?php $team = [ ['id' => 1, 'name' => 'Team A'], ['id' => 2, 'name' => 'Team B'], ['id' => 3, 'name' => 'Team C'], ]; $people = [ ['id' => 1, 'name' => 'Mark Hamill', 'team' => 1], ['id' => 2, 'name' => 'Nicolas Cage', 'team' => 2], ['id' => 3, 'name' => 'Tom Cruise', 'team' => 3], ['id' => 4, 'name' => 'Tom Hanks', 'team' => 1], ['id' => 5, 'name' => 'Brad Pitt', 'team' => 2], ['id' => 6, 'name' => 'Paul Smith', 'team' => 3], ['id' => 7, 'name' => 'Matt Daemon', 'team' => 1], ['id' => 8, 'name' => 'Robert Redford', 'team' => 2], ]; $teampeople = array_column($people, "team"); Foreach($team as &$t){ $t['members'] = array_values(array_intersect_key($people, array_intersect($teampeople, [$t['id']]))); } Var_dump($team);
Output for git.master_jit, git.master, rfc.property-hooks
array(3) { [0]=> array(3) { ["id"]=> int(1) ["name"]=> string(6) "Team A" ["members"]=> array(3) { [0]=> array(3) { ["id"]=> int(1) ["name"]=> string(11) "Mark Hamill" ["team"]=> int(1) } [1]=> array(3) { ["id"]=> int(4) ["name"]=> string(9) "Tom Hanks" ["team"]=> int(1) } [2]=> array(3) { ["id"]=> int(7) ["name"]=> string(11) "Matt Daemon" ["team"]=> int(1) } } } [1]=> array(3) { ["id"]=> int(2) ["name"]=> string(6) "Team B" ["members"]=> array(3) { [0]=> array(3) { ["id"]=> int(2) ["name"]=> string(12) "Nicolas Cage" ["team"]=> int(2) } [1]=> array(3) { ["id"]=> int(5) ["name"]=> string(9) "Brad Pitt" ["team"]=> int(2) } [2]=> array(3) { ["id"]=> int(8) ["name"]=> string(14) "Robert Redford" ["team"]=> int(2) } } } [2]=> &array(3) { ["id"]=> int(3) ["name"]=> string(6) "Team C" ["members"]=> array(2) { [0]=> array(3) { ["id"]=> int(3) ["name"]=> string(10) "Tom Cruise" ["team"]=> int(3) } [1]=> array(3) { ["id"]=> int(6) ["name"]=> string(10) "Paul Smith" ["team"]=> int(3) } } } }

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:
39.65 ms | 405 KiB | 8 Q