$strArray= array("market";"cars");
$index=0;
for ($index=0;$index<2;$index++){ // difficulties are that i get errorin for and if loop.
//because the code works in browser without it ps:there is an html code following the php code
if($_POST['guess']===$strArray[$index]){
$message="good answer";
}
else{
$message="wrong answer";
$shuffle=str_shuffle($strArray[$index+1]);
}
?>
// if语句给我带来了错误 谢谢你的帮助
答案 0 :(得分:0)
数组定义中存在语法错误 改变它
$strArray= array("market";"cars");
到
$strArray= array("market","cars");`
此外,您必须在循环中传递数组长度
$length = count($strArray);
for ($index=0;$index<$length;$index++){
答案 1 :(得分:0)
您的数组中存在语法错误,并且您不需要循环。使用in_array()
<?php
$strArray = array("market", "cars");
$guess = $_POST['guess'];
if (in_array($guess, $strArray)) {
$message = "good answer";
} else {
$message = "wrong answer";
}
?>