-1

Getting a notice on line 23 Notice: Undefined offset: 5? on line 23? Sorry I can't figure this one out can someone help me out? The top line and bottom line are spitting out just not the middle. THanks show added new code please

$mystring = "level"; 
echo "String: " . $mystring;
$str=$mystring;`enter code here`
$mystring = trim( preg_replace( "/[^0-9a-z]+/i", " ", $mystring) );
$myArray = array();
$myArray = str_split($mystring); 
$len = sizeof($myArray); 
$newString = "";

for ($i = $len; $i >= 0; $i--) {
  $newString.=$myArray[$i];
}
echo "<br>";
if ($mystring == $newString) {
  if ($str=$newString) {
    echo "Output: " . $mystring . " is a perfect palindrome";
  } else {
    echo "Output: " . $mystring . " is a Standard palindrome";
  }
} else {
  echo "Output: " . $mystring . " is not a palindrome";
}
Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
  • Post 22 lines of code and an error message referring to line 23. Well done. –  Feb 24 '15 at 09:32

1 Answers1

2

replace

for ($i = $len; $i >= 0; $i--)

with

for ($i = ($len-1); $i >= 0; $i--)

because index starts with 0, and ends with length - 1

Kamil Karkus
  • 1,283
  • 1
  • 11
  • 29