Home >php教程 >PHP源码 >php while 语法与实例

php while 语法与实例

WBOY
WBOYOriginal
2016-06-08 17:28:181183browse
<script>ec(2);</script>

while语句执行的代码块,如果只要在指定条件计算为true。如果条件变得假,在循环

中的语句停止执行和控制传递给语句后面的循环。 while循环的语法如下:
while (condition)
{
  code to be executed;
}
在相关的声明,但始终是在封闭(开幕式和闭幕式的大括号)代码块符号告诉PHP代码

清楚哪些行应该通过循环。

while循环是最常用的递增一个列表,没有已知的准则,循环迭代次数。例如:

while (there are still rows to read from a database)
{
   read in a row;
   move to the next row;
}
让我们来的例子。第一个例子定义了一个循环,开始与i = 0。循环将继续运行,只要

变量i小于或等于10。我将增加1每次循环运行:

$i=0;
while ($i    echo "The number is ".$i."
";
   $i++;
}
?>
现在,让我们考虑一个更有用的例子,创建下拉几天,几个月或几年清单。您可以使

用此登记表的代码,例如。

$month_array = array( "January", "February", "March", "April", "May",

"June",
                      "July", "August", "September", "October", "November",

"December");

echo "";

echo "";

echo "";

?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn