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);

preferences:
23.09 ms | 404 KiB | 5 Q