sql语句中的in用法示例_PHP中的循环语句和示例

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.

只要一条语句保持为truewhile语句就会执行特定的代码块。

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用法示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值