嗨,我只是想知道如何在if语句工作(循环)? 我希望页面能够显示1到10之间的数字,并显示对数字1和2的特别注释。 非常感谢!if语句在while循环中?
<?php
$x=1;
while($x <= 10) {
echo "". $x . "<br />";
$x = $x + 1; }
if ($x = 1) {
echo "".$comment."";
$comment = "this is one!";}
elseif ($x = 2) {
echo "".$comment."";
$comment = "this is two!";}
?>
只需在条件周围包裹'while'循环即可。你也在声明'$ comment'之前回应。 – Parfait