3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(0); function f($s){while(!$a&&++$i<strlen($s))for($j=0;$b=substr($s,$j++,$i);)strpos($s,$b)==strrpos($s,$b)&&($a[]=$b);return$a;} echo "------\n"; var_dump(f("")); echo "\n"; // -> [""] var_dump(f("abcaa")); // -> ["b","c"] var_dump(f("rererere")); echo "\n"; // -> ["ererer"] var_dump(f("asdfasdfd")); echo "\n"; // -> ["fa","fd"] var_dump(f("ffffhhhhfffffhhhhhfffhhh")); echo "\n"; // -> ["hffff","fffff","hhhhh","hfffh"] var_dump(f("asdfdfasddfdfaddsasadsasadsddsddfdsasdf")); echo "\n"; // -> ["fas","fad","add","fds"] echo "------\n";
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.30, 7.4.0 - 7.4.23, 8.0.0 - 8.0.10, 8.1rc1 - rc2
------ NULL array(2) { [0]=> string(1) "b" [1]=> string(1) "c" } array(1) { [0]=> string(6) "ererer" } array(2) { [0]=> string(2) "fa" [1]=> string(2) "fd" } array(4) { [0]=> string(5) "hffff" [1]=> string(5) "fffff" [2]=> string(5) "hhhhh" [3]=> string(5) "hfffh" } array(4) { [0]=> string(3) "fas" [1]=> string(3) "fad" [2]=> string(3) "add" [3]=> string(3) "fds" } ------
Output for 4.3.1 - 4.3.11, 4.4.0 - 4.4.9
------ NULL array(2) { [0]=> string(1) "b" [1]=> string(1) "c" } NULL array(1) { [0]=> string(2) "fd" } NULL NULL ------

preferences:
70.95 ms | 460 KiB | 5 Q