sql語句中的in用法示例
循環 (Loops)
Imagine that we need a program that says "hello world" 100 times. It's quite stressful and boring to write the statement -- echo "hello world" — 100 times in PHP. This is where loop statement facilitates the work for us.
想象一下,我們需要一個說“ hello world” 100次的程序。 編寫該語句非常無聊,很無聊-echo“ hello world” -在PHP中是100次。 這是循環語句為我們簡化工作的地方。
A loop statement is a statement that execute as long as a particular condition is valid and stops when that condition is invalid.
循環語句是只要特定條件有效就執行的語句,并在該條件無效時停止執行 。
Let's look at the different loops in PHP.
讓我們看一下PHP中的不同循環 。
1)while循環 (1) The while loop)
The while statement executes a particular block of code as long as a statement remains true.
只要一條語句保持為true , while語句就會執行特定的代碼塊。
Syntax:
句法:
while (condition true) {
code to be executed;
}
Example:
例:
We want to display the number 1 to 5.
我們要顯示數字1到5。
<?php
$x = 1;
while ($x <= 5) {
echo "Number is: $x <br>";
$x++;
}
?>
Output
輸出量
Number is :1
Number is :2
Number is :3
Number is :4
Number is :5
2)do ... while循環 (2) The do...while loop)
The do...while loop is the same as the while loop but for that it executes your code atleast once even if the condition is false before checking the condition to true and continues executing as the statement remains true.
do ... while循環與while循環相同,但是do ... while循環即使條件為false也會至少執行一次代碼,然后再將條件檢查為true并繼續執行,因為語句保持為true 。
Syntax:
句法:
do {
code to be executed;
} while (condition is true);
Example:
例:
In this example we will repeat the example above but demonstrate how the do..while loop executes your code atleast once whether true or false before checking the condition.
在此示例中,我們將重復上面的示例,但演示在檢查條件之前do..while循環如何至少一次執行您的代碼,無論是true還是false。
<?php
$x = 1;
do {
echo "Number is: $x <br>";
$x++;
} while ($x >= 5);
?>
Output
輸出量
Number is :1
3)for循環 (3) The for loop)
The for loop works as the while loop but a difference in syntax, in this loop all the things like counter initialization, condition, increment and decrement statements are placed together separated by the semicolon.
for循環用作while循環,但在語法上有所不同,在該循環中,將計數器初始化,條件,遞增和遞減語句之類的所有內容放在一起,并用分號隔開。
Syntax:
句法:
for (initialization counter; test counter; increment/decrement counter) {
code to be executed;
}
The initialization counter is used to set the initial value.
初始化計數器用于設置初始值。
Test counter or condition determines the execution process, if true the loop continues if false the loop stops.
測試計數器或條件確定執行過程,如果為true,則循環繼續;如果為false,則循環停止。
The increment/decrement counter, used to increments or decrements the initial value.
遞增/遞減計數器 ,用于遞增或遞減初始值。
Example:
例:
We go with our example again listing numbers from 1 to 5 with the for loop
我們再次使用示例,使用for循環列出從1到5的數字
<?php
for ($x = 1;$x <= 5;$x++) {
echo "Number is: $x <br>";
}
?>
Output
輸出量
Number is :1
Number is :2
Number is :3
Number is :4
Number is :5
翻譯自: https://www.includehelp.com/php/loop-statements.aspx
sql語句中的in用法示例