3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = Array(0 => Array('member_id' => 6, 'total' => 1, 'sorting' => 0), 1 => Array('member_id' => 7, 'total' => 2, 'sorting' => 1) ); $b = Array(0 => Array('member_id' => 2, 'total' => 3), 1 => Array('member_id' => 6, 'total' => 1), 2 => Array('member_id' => 7, 'total' => 2) ); /* * first, store all records with matching member_id */ $c = []; foreach ($b as $key0 => $value0) { foreach ($a as $key1 => $value1) { // matching 'member_id'? if ($value0['member_id'] === $value1['member_id']) { // inject record into store $c $c[] = $a[$key1]; } } } /* * second, inject non-matching records from $b into store $c */ $ids = array_column($c, 'member_id'); foreach ($b as $key => $value) { if (!in_array($value['member_id'], $ids)) { $sorting = max(array_column($c, 'sorting')) + 1; $value['sorting'] = $sorting; $c[] = $value; } } echo '<pre>'; print_r($c); echo '</pre>';
Output for git.master, git.master_jit, rfc.property-hooks
<pre>Array ( [0] => Array ( [member_id] => 6 [total] => 1 [sorting] => 0 ) [1] => Array ( [member_id] => 7 [total] => 2 [sorting] => 1 ) [2] => Array ( [member_id] => 2 [total] => 3 [sorting] => 2 ) ) </pre>

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:
116.78 ms | 406 KiB | 5 Q