3v4l.org

run code in 500+ PHP versions simultaneously
<?php $src = ["apple", "cherry", "grape", "lemon", "orange", "strawberry"]; $dst = ["apple", "banana", "cherry", "orange", "pear"]; $src = array_combine($src, $src); $dst = array_combine($dst, $dst); $combined_items = $src + $dst; ksort($combined_items); $result = []; foreach ($combined_items as $item) { $result[] = [ $src[$item] ?? null, $dst[$item] ?? null ]; } echo "<table border=1> "; foreach ($result as $i => [$s, $d]) { printf( "<tr> <td>%d</td> <td>%s</td> <td>%s</td> </tr>\n", ++$i, $s, $d ); } echo "</table>";

preferences:
82.53 ms | 1409 KiB | 5 Q