[英]syntax error: unexpected "echo " in PHP
there is unexpected echo on $_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
$_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
上有意外的回声$_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
$_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
line.线。 please help
请帮忙
this is my code:这是我的代码:
<?php
session_start();
$soal = $_SESSION['soal'];
$no = $_SESSION['no'];
if(isset($_POST['next'])){
$_SESSION['jawab'][] = $_POST['option'];
if($_POST['option'] == $soal[$no-2]['kunci']){
$_SESSION['correctAnswer'] = $soal[$no-2]['kunci']; // add sthing like this
}
}
if(isset($soal[$no-1])){
?>
<!DOCTYPE html>
<html>
<head>
<title>Latihan Soal</title>
</head>
<body>
<a href="index.php">Kembali ke soal 1</a>
<form action="" method="POST">
<p>
<?php
echo $no.". "; $_SESSION['no']++;
echo $soal[$no-1]['soal'];
$jawaban = $_SESSION['option'][$no-1];
shuffle($jawaban);
?>
</p>
<?php
for ($i=0; $i < 4; $i++) {
?>
<input type="radio" name="option" value="<?php echo $jawaban[$i]; ?>" required/> <?php echo $jawaban[$i]; ?></br>
<?php
$_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
}
?>
<input type="submit" name="next" value="next">
</form>
</body>
</html>
<?php
}else{
header("location:result.php");
}
?>
There's a syntax error
in your ternary operator:您的三元运算符中存在
syntax error
:
$_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
You should put echo before the ternary operator like this您应该像这样在三元运算符之前放置 echo
echo $_SESSION['correctAnswer'] == $jawaban[$i] ? " correct" : " incorrect";
Replace this替换这个
$_SESSION['correctAnswer'] == echo $jawaban[$i]; ? " correct" : " incorrect";
with和
echo (($_SESSION['correctAnswer'] == $jawaban[$i]) ? " correct" : " incorrect");
from horrible PHP manual ( http://php.net/manual/en/function.echo.php ):来自可怕的 PHP 手册( http://php.net/manual/en/function.echo.php ):
echo is not actually a function (it is a language construct)
echo 实际上不是一个函数(它是一个语言结构)
So, it does not return anything.所以,它不会返回任何东西。
And as it is a language construct - you got your error here.由于它是一种语言结构 - 您在这里遇到了错误。 As if you have an unexpected 'if' or 'while' there.
好像你有一个意想不到的“如果”或“时间”。 It doesn't make sense to PHP interpreter.
PHP解释器没有意义。
Remove that echo.去掉那个回声。 as @splash58 said.
正如@splash58 所说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.