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