递减 3 数字的概念是通过将第一个数字与其他两个数字进行比较,并且第一个数字应该大于其他数字,因此如果第二个数字大于交换到第一个数字,我们将第一个数字与第二个数字进行比较,同样适用于第一个数字和第三个数字之后处理第一个数字将大于二。检查剩余的两个变量并再次比较在第二个变量中分配更大的数字。这样它是递减的。
<?php
function descending(){
$num1 = $_GET['num1']; // Let suppose $num1 = 1
$num2 = $_GET['num2']; // Let suppose $num2 = 2
$num3 = $_GET['num3']; // Let suppose $num3 = 3
if ($num1 < $num2) { // here $num1 (1) is less than $num2(2)
$temp = $num1; // $temp(2)
$num1 = $num2; // copy $temp(2) to $num1(2)
$num2 = $temp; // this process swap $num1(2) and $num(1)
}
if ($num1 < $num3) { // here $num1(2) and $num3(3) which is less so swap
$temp = $num1;
$num1 = $num3;
$num3 = $temp; //After swap $num1(3) & $num3(2)
}
//now at this time $num1 greatest among other two variable
if ($num2 < $num3) { //$num2(1) and $num3(2) so swap
$temp = $num2;
$num2 = $num3;
$num3 = $temp; // this way $num2 will be greater
}
echo "<br>";
//first error: After descending value store in $num1, $num2, and $num3
//not in $num1a, $num2a, and $num3a these variable.
echo $num1 . " , " . $num2 . " , " . $num3;
echo "<br>";
} // second error missing this curly bracket.
?>
希望你能理解并忽略我糟糕的英语。快乐编码:)