3v4l.org

run code in 300+ PHP versions simultaneously
<?php $firstArray = array('22','24','23','26','22','24','23','26'); $secondArray = array('John','Smith','Mark','Steve','George','Nick','Sean','Brad'); $thirdArray = array('A','B','D','E','F','G','H','I'); $new1 = []; $new2 = []; $new3 = []; foreach ($firstArray as $index => $value) { if (!isset($ref[$value])) { $new1[] = &$ref[$value][0]; $new2[] = &$ref[$value][1]; $new3[] = &$ref[$value][2]; } $ref[$value][0] = $value; $ref[$value][1] = $secondArray[$index]; $ref[$value][2] = $thirdArray[$index]; } var_dump($new1, $new2, $new3);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array(4) { [0]=> &string(2) "22" [1]=> &string(2) "24" [2]=> &string(2) "23" [3]=> &string(2) "26" } array(4) { [0]=> &string(6) "George" [1]=> &string(4) "Nick" [2]=> &string(4) "Sean" [3]=> &string(4) "Brad" } array(4) { [0]=> &string(1) "F" [1]=> &string(1) "G" [2]=> &string(1) "H" [3]=> &string(1) "I" }

preferences:
92.64 ms | 403 KiB | 91 Q