用if语句对数字进行排序

时间:2019-04-02 18:47:22

标签: php if-statement

我尝试构建此代码并创建可以在正确打印后打印的错误。我有以下代码:

<?php
$A=3;
$B=10;
$C=5;

if ($A<=$B){
    if($C<=$A){
        echo $C,"</br>",$A,"</br>",$B;
    }
    if($B<=$C){
        echo $A,"</br>",$B,"</br>",$C;
    }
    else {
        echo $A,"</br>",$C,"</br>",$B;
    }
}
    if ($C<=$B){
        echo $C,"</br>",$B,"</br>",$A;

    if ($C<=$A){
        echo $B,"</br>",$C,"</br>",$A;
    }
    else{
        echo $B,"</br>",$A,"</br>",$C;
    }}



?>

我以这个为答案:

3
5
105
10
3

代替

3
5
10 

必须打印的 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试此代码,您已经忘记了其他代码:

$A=3;
$B=10;
$C=5;


if ($A<=$B){
    if($C<=$A){
        echo $C,"</br>",$A,"</br>",$B;
    }
    if($B<=$C){
        echo $A,"</br>",$B,"</br>",$C;
    }
    else {
        echo $A,"</br>",$C,"</br>",$B;
    }
}
else {
    if ($C<=$B){
        echo $C,"</br>",$B,"</br>",$A;
    }
    if ($C<=$A){
        echo $B,"</br>",$C,"</br>",$A;
    }
    else {
        echo $B,"</br>",$A,"</br>",$C;
    }
}