2015-02-24 72 views
-1

獲取第23行通知 注意:未定義偏移量:5?在23號線? 對不起,我不能找出這個人可以幫助我嗎? 頂線和底線正在吐出,而不是中間。感謝節目增添了新的代碼,請PHP未定義集合

$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"; 
} 
+0

後22行代碼,並結束錯誤消息指的是第23行。幹得好。 – 2015-02-24 09:32:40

回答

2

更換

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

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

因爲指數與0開始,以length - 1