只需要一个简单的if ... else语句来工作
问题描述:
只是试图获得一个简单的if ... else语句来工作。最初,我们得到:只需要一个简单的if ... else语句来工作
<?php
$IntVariable = 75;
($IntVariable > 100) ? $Result = '$IntVariable is
greater than 100'
: $Result = '$IntVariable is less than or equal
to 100';
echo "<p>$Result</p>";
?>
这需要变成一个if ... else语句。到目前为止,我已经写了:
<?php
$IntVariable = 75;
if ($IntVariable > 100) {
$Result = '$IntVariable is greater than 100';
}
else {
$Result = '$IntVariable is less than or equal to 100';
}
else {
echo "<p>$Result</p>";
}
?>
我真的新到PHP所以我可能失去了一些东西很简单......
答
为什么又一个else
到echo $result
,如果您有很多条件可以使用else if
..否则,给else
<?php
$IntVariable = 75;
if ($IntVariable > 100) {
$Result = '$IntVariable is greater than 100';
}
else {
$Result = '$IntVariable is less than or equal to 100';
}
echo "<p>$Result</p>";
?>
你有两个else语句。 – RSon1234
如果你要使用许多其他语句,你应该使用elseif – fizzi