<?php
$x = 4;
$y = 5;
function greaterOrSmaller($x,$y){
if($x>$y){
return 1;
}elseif ($x==$y) {
return 0;
}else{
return -1;
}
}
if(greaterOrSmaller($x,$y)==1){
echo"{$x} is greater than {$y}";
}elseif(greaterOrSmaller($x,$y)==0){
echo"{$x} is equal to {$y}";
}else(greaterOrSmaller($x,$y)==-1){
echo"{$x} is smaller than {$y}";
}
您在上次比较中忘记了elseif表达式中的if
试试这个:
<?php
$x = 4;
$y = 5;
function greaterOrSmaller($x,$y){
if($x>$y){
return 1;
}elseif ($x==$y) {
return 0;
}else{
return -1;
}
}
if(greaterOrSmaller($x,$y)==1){
echo"{$x} is greater than {$y}";
}elseif(greaterOrSmaller($x,$y)==0){
echo"{$x} is equal to {$y}";
}elseif(greaterOrSmaller($x,$y)==-1){
echo"{$x} is smaller than {$y}";
}