3v4l.org

run code in 300+ PHP versions simultaneously
<?php function is_palindrome($str) { $len = strlen($str); if ($len < 2) { // strings of 0 or 1 characters are palindromes return true; } elseif ($str[0] != $str[$len-1]) { // first character doesn't match last character, so not a palindrome return false; } else { // first character is equal to last character, // so see if the rest of the string is a palindrome return is_palindrome(substr($str, 1, $len - 2)); } } foreach (['rotor', 'a', 'deed', 'hello', 'xyyz'] as $str) { echo "\"$str\" is" . (is_palindrome($str) ? "" : " not") . " a palindrome\n"; } function is_palindrome_broken($str) { $len = strlen($str); if ($len < 2) { // strings of 0 or 1 characters are palindromes return true; } elseif ($str[0] != $str[$len-1]) { // first character doesn't match last character, so not a palindrome return false; } else { // first character is equal to last character, // so see if the rest of the string is a palindrome is_palindrome_broken(substr($str, 1, $len - 2)); } } foreach (['rotor', 'a', 'deed', 'hello', 'xyyz'] as $str) { echo "\"$str\" is" . (is_palindrome_broken($str) ? "" : " not") . " a palindrome\n"; }
Output for 8.1.6 - 8.1.33, 8.2.10 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
"rotor" is a palindrome "a" is a palindrome "deed" is a palindrome "hello" is not a palindrome "xyyz" is not a palindrome "rotor" is not a palindrome "a" is a palindrome "deed" is not a palindrome "hello" is not a palindrome "xyyz" is not a palindrome
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
118.78 ms | 407 KiB | 5 Q