PHP循环语句

定义静态变量: static $name;
变量的变量: $a = “Hello”;
          $$a = “world”; //相当于 $Hello = “world”;

变量的函数:
         <?php
              function myCallBackFunction()
              {
                  print (“Hello from callback!”);
              }
              function myFunction($CallBack)
              {
                  $CallBack();
              }
              myFunction(“myCallBackFunction“);
         ?>
         其执行结果为: Hello from callback!
 
if 语句:
         <?php
              if(file_exists(“文件路径”)
              {
                  echo “字符串提示”;
                  readfile(“文件路径”); //读出文件内容.
                  echo “字符串提示”;
              }
         ?>
 
while 循环语句:
         <?php
              $i = 1;
              while($i <= 10)
              {
                  print $i++;
                  echo “.以后不敢了!<br>\n”;
              }
         ?>
         <?php
              $i = 1;
              while($i <= 10):
                  print $i++;
                  echo “.以后不敢了!<br>\n”;
              endwhile;
         ?>
         <?php
             $i = 1;
             do
             {
                 $i++;
                 echo “.以后不敢了!<br>\n”;
             }
             while($i <= 10);
         ?>
for 循环语句:
         <?php
             for($i = 1;$i <= 10;$i++)
             {
                 echo “.以后不敢了!<br>\n”;
             }
         ?>
switch 循环:
         <?php
             switch(date(“D”))
             {
                 case “Mon”:
                      echo “今天星期一!”;
                      break;
                        .
                        .
                        .
                 default:
                      echo “今天放假!”;
                      break;
             }
         ?>
break continue 流程控制:
     break 跳出当前循环:
           <?php
               $i = 0;
               while($i < 10)
               {
                   if($arr[$i] == “stop”)
                   {
                       break;
                   }
               }
           ?>
    continue 立即停止目前执行的循环,并回到循环的条件判断处.
           <?php
               while(list($key,$value) = each($arr))
               {
                  if($key % 2) //略过偶数
                  {
                      continue;
                  }
                  do_something_odd($value);
               }
           ?>

发表评论