mardi 2 avril 2019

sort numbers with if statement in php

I try to build this code and create a bug that print and after the correct printing. I've got this code:

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

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

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


?>

And I take this as an answer: 3 5 105 10 3 instead of 3 5 10 that must to print How could I correct that problem? Thank you

Aucun commentaire:

Enregistrer un commentaire