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 git.master, git.master_jit, rfc.property-hooks
"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

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.93 ms | 401 KiB | 8 Q