下面的代码显示了嵌套的 while 循环,但它的效率不是很高。假设我想扩展代码以包含 100 个嵌套的 while 循环。有没有更好的方法来完成这项任务?
<?php
$count = 1;
$num = 1;
$options=3;
while ( $num <=$options )
{
echo "(".$num . ") ";
$num1 = 1;
$options1=3;
while ( $num1 <=$options1 )
{
echo "*".$num1 . "* ";
$num2 = 1;
$options2=3;
while ( $num2 <=$options2 )
{
echo "@".$num2 . "@ ";
$num3 = 1;
$options3=3;
while ( $num3 <=$options3 )
{
echo $num3 . " ";
$num3++;
$count++;
}
echo "<br />";
$num2++;
}
echo "<br />";
$num1++;
}
echo "<br />";
$num++;
}
echo $count;
?>