3v4l.org

run code in 300+ PHP versions simultaneously
<?php $postcard = 'paccoi'; $car = 'coi'; $arr_postcard = str_split($postcard); $arr_car = str_split($car); function array_diff_once($array1, $array2) { foreach($array2 as $a) { $pos = array_search($a, $array1); if($pos !== false) { unset($array1[$pos]); } } return $array1; } $uncommon = count($arr_postcard) >= count($arr_car) ? array_diff_once($arr_postcard,$arr_car) : array_diff_once($arr_car,$arr_postcard); echo 'Letters not in common: ' . implode(' - ', $uncommon) . PHP_EOL; function array_intersect_once($array1, $array2) { $array = []; foreach($array1 as $a) { $pos = array_search($a, $array2); if($pos !== false) { $array[] = $a; } } return $array; } $common = count($arr_postcard) >= count($arr_car) ? array_intersect_once($arr_car,$arr_postcard) : array_intersect_once($arr_postcard,$arr_car); echo 'Letters in common: ' . implode(' - ', $common) . PHP_EOL;
Output for 5.4.33, 5.6.11, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
Letters not in common: p - a - c Letters in common: c - o - i
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Letters not in common: p - a - c Letters in common: c - o - i
Output for 5.2.17
Parse error: syntax error, unexpected '[' in /in/lY755 on line 26
Process exited with code 255.
Output for 4.3.7
Parse error: parse error, unexpected '[' in /in/lY755 on line 26
Process exited with code 255.

preferences:
159.92 ms | 401 KiB | 156 Q