2017-02-16 37 views
-1

只是試圖獲得一個簡單的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所以我可能失去了一些東西很簡單......

+0

你有兩個else語句。 – RSon1234

+0

如果你要使用許多其他語句,你應該使用elseif – fizzi

回答

1

爲什麼又一個elseecho $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>"; 

?>