如何用if(){},else{}.來寫這段代碼?
<?php?
? ? ?$maxLine = 4; //每排人數(shù)
$no = 17;//學生編號
$line =ceil($no/$maxLine);
$row =$no%$maxLine?$no%$maxLine:$maxLine;/*語法:條件 ? 結(jié)果1 : 結(jié)果2 (如果條件為真,返回結(jié)果1,否則返回結(jié)果2。) %是取模的意思,即求余數(shù)。如果成立,返回no%$maxLine,否則返回$maxLine。(即學生編號除以每排人數(shù)有余數(shù),返回余數(shù),否則返回每排人數(shù)。)*/
echo "編號<br/>".$no."</b>的座位在第<b>"."<br/>".$line."</b>排第<b>".$row."</b>個位置"."<br/>";
? ? ?$maxLine = 4; //每排人數(shù)
? ? ?$no = 19;//學生編號
? ? ?
? ?
$row =$no%$maxLine?$no%$maxLine:$maxLine;
? ? ?if($no%$maxLine>0){$row = ($no%$maxLine);
? ? ?}
? ? ?else{$row = $maxLine;
? ? ?}
? ? ?echo $row;
? ? ?
?>