• php循环


    while

    例子:

    /* example 1 */
    $a = 0;
    while (true) {
        $a++;
        echo $a.'<br>';
        if($a >= 10){
            break; //打断循环
        }
    }
    
    /* example 2 */
    $a = 0;
    while ($a < 10) {
        $a++;
        echo $a.'<br>';
         
    }
    
    
    /* example 3 */
    $arr = array("orange", "banana", "apple", "raspberry");
    $i = 0;
    while ($i < count($arr)) {
       $a = $arr[$i];
       echo $a .",";
       $i++;
    }
    
    /* example 4 */
    $myArray=['aa','bb','cc','dd'];
     
    while (list ($key, $val) = each ($myArray)) {
        echo "$key=>$val,";
    }

    do-while

    例子:

    $a=0;
    
    do{
        $a++;
        echo $a;
    }
    while ($a < 10);

    for

    例子:

    /* example 1 */
    
    for ($i = 1; $i <= 10; $i++) {
        echo $i;
    }
    
    echo "<br>";
    
    /* example 2 */
    
    for ($i = 1; ; $i++) {
        if ($i > 10) {
            break;
        }
        echo $i;
    }
    
    echo "<br>";
    
    /* example 3 */
    
    $i = 1;
    for (;;) {
        if ($i > 10) {
            break;
        }
        echo $i;
        $i++;
    }
    
    echo "<br>";
    
    /* example 4 */
    
    for ($i = 1, $j = 0; $i <= 10; $j += $i, print $i, $i++);
    

    foreach

    例子:

    $arr = array(1, 2, 3, 4);
    
    /* example 1 */
    foreach ($arr as $value) {
    	echo $value.'<br>';
    }
    
    /* example 2 */
    foreach ($arr as $key => $val) {
        echo "$key=>$val,";
    }
    
  • 相关阅读:
    jquery ajax 分页2
    jquery('tr','div')和jquery('tr,div')
    ajax代码及简单封装
    jquery ajax 分页
    iframe加载的文档高度
    Bootstrap
    web 打印分页技巧
    web 后台打印
    存储过程自动更新ID
    Leetcode 105
  • 原文地址:https://www.cnblogs.com/fan-bk/p/9446644.html
Copyright © 2020-2023  润新知