zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然PHP-MySQL-JavaScript学习笔记:PHP中的表达式和控制流

    <?php
      $level = $score = $time = 0;
    ?>
    <?php
      $month = "March";
    
      if ($month == "March") echo "It's springtime";
    ?>
    <?php
      $a = "1000";
      $b = "+1000";
    
      if ($a == $b)  echo "1";
      if ($a === $b) echo "2";
    ?>
    <?php
      $a = "1000";
      $b = "+1000";
    
      if ($a != $b)  echo "1";
      if ($a !== $b) echo "2";
    ?>
    <?php
      $a = 2; $b = 3;
      if ($a > $b)  echo "$a is greater than $b<br>";
      if ($a < $b)  echo "$a is less than $b<br>";
      if ($a >= $b) echo "$a is greater than or equal to $b<br>";
      if ($a <= $b) echo "$a is less than or equal to $b<br>";
    ?>
    <?php
      $a = 1; $b = 0;
    
      echo ($a AND $b) . "<br>";
      echo ($a or $b)  . "<br>";
      echo ($a XOR $b) . "<br>";
      echo !$a         . "<br>";
    ?>
    <?php
      if ($finished == 1 or getnext() == 1) exit;
    ?>
    <?php
      $gn = getnext();
    
      if ($finished == 1 or $gn == 1) exit;
    ?>
    <?php
      if ($bank_balance < 100)
      {
        $money         = 1000;
        $bank_balance += $money;
      }
    ?>
    <?php
      if ($bank_balance < 100)
      {
        $money         = 1000;
        $bank_balance += $money;
      }
      else
      {
        $savings      += 50;
        $bank_balance -= 50;
      }
    ?>
    <?php
      if ($bank_balance < 100)
      {
          $money         = 1000;
          $bank_balance += $money;
      }
      elseif ($bank_balance > 200)
      {
          $savings      += 100;
          $bank_balance -= 100;
      }
      else
      {
          $savings      += 50;
          $bank_balance -= 50;
      }
    ?>
    <?php
      $page = "test";
    
      if     ($page == "Home")  echo "You selected Home";
      elseif ($page == "About") echo "You selected About";
      elseif ($page == "News")  echo "You selected News";
      elseif ($page == "Login") echo "You selected Login";
      elseif ($page == "Links") echo "You selected Links";
      else                      echo "Unrecognized selection";
    ?>
    <?php
      switch ($page)
      {
          case "Home":  echo "You selected Home";
              break;
          case "About": echo "You selected About";
              break;
          case "News":  echo "You selected News";
              break;
          case "Login": echo "You selected Login";
              break;
          case "Links": echo "You selected Links";
              break;
      }
    ?>
    <?php
    switch ($page)
    {
        case "Home":
            echo "You selected Home";
            break;
        case "About":
            echo "You selected About";
            break;
        case "News":
            echo "You selected News";
            break;
        case "Login":
            echo "You selected Login";
            break;
        case "Links":
            echo "You selected Links";
            break;
        default:
            echo "Unrecognized selection";
            break;
    }
    ?>
    <?php
      switch ($page):
          case "Home":
              echo "You selected Home";
              break;
      
          // etc...
      
          case "Links":
              echo "You selected Links";
              break;
      endswitch;
    ?>
    <?php
      echo $fuel <= 1 ? "Fill tank now" : "There's enough fuel";
    ?>
    <?php
      $enough = $fuel <= 1 ? FALSE : TRUE;
    ?>
    <?php
      $fuel = 10;
    
      while ($fuel > 1)
      {
        // Keep driving ?    echo "There's enough fuel";
      }
    ?>
    <?php
      $count = 1;
    
      while ($count <= 12)
      {
        echo "$count times 12 is " . $count * 12 . "<br>";
        ++$count;
      }
    ?>
    <?php
      $count = 0;
    
      while (++$count <= 12)
        echo "$count times 12 is " . $count * 12 . "<br>";
    ?>
    <?php
      $count = 1;
    
      do
        echo "$count times 12 is " . $count * 12 . "<br>";
      while (++$count <= 12);
    ?>
    <?php
      $count = 1;
      
      do {
        echo "$count times 12 is " . $count * 12;
        echo "<br>";
      } while (++$count <= 12);
    ?>
    <?php
      for ($count = 1 ; $count <= 12 ; ++$count)
        echo "$count times 12 is " . $count * 12 . "<br>";
    ?>
    <?php
      for ($count = 1 ; $count <= 12 ; ++$count)
      {
        echo "$count times 12 is " . $count * 12;
        echo "<br>";
      }
    ?>
    <?php
      $fp = fopen("text.txt", 'wb');
    
      for ($j = 0 ; $j < 100 ; ++$j)
      {
        $written = fwrite($fp, "data");
    
        if ($written == FALSE) break;
      }
    
      fclose($fp);
    ?>
    <?php
      $j = 10;
    
      while ($j > -10)
      {
        $j--;
    
        if ($j == 0) continue;
    
        echo (10 / $j) . "<br>";
      }
    ?>
    <?php
      $a = 56;
      $b = 12;
      $c = $a / $b;
    
      echo $c;
    ?>
    <?php
      echo "a: [" . (20 > 9) . "]<br>";
      echo "b: [" . (5 == 6) . "]<br>";
      echo "c: [" . (1 == 0) . "]<br>";
      echo "d: [" . (1 == 1) . "]<br>";
    ?>
    <?php // test2.php
      echo "a: [" . TRUE  . "]<br>";
      echo "b: [" . FALSE . "]<br>";
    ?>
    <?php
      $myname = "Brian";
      $myage  = 37;
    
      echo "a: " . 73      . "<br>"; // Numeric literal
      echo "b: " . "Hello" . "<br>"; // String literal
      echo "c: " . FALSE   . "<br>"; // Constant literal
      echo "d: " . $myname . "<br>"; // String variable
      echo "e: " . $myage  . "<br>"; // Numeric variable
    ?>
    <?php
      $day_number       = 340;                // Assignment by Value
      $days_to_new_year = 366 - $day_number;  // Assignment by Expression
    
      if ($days_to_new_year < 30)             // Condition
      {
        echo "Not long now till new year";    // Statement
      }
    ?>
  • 相关阅读:
    MySQL数据库备份
    执行SDK的aapt报错./aapt: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./aapt)
    ftp删除目录和文件,目录下有文件删除提示【550 Remove directory operation failed.】
    Spring mvc接收中文参数值乱码(tomcat配置问题)
    python3获得命令行输入的参数
    Java反射、动态加载(将java类名、方法、方法参数当做参数传递,执行方法)
    java定义object数组(可以存储String或int等多种类型)
    java方法中增加不固定参数
    ibatis和myBatis打印sql语句的log4j配置文件
    spring依赖注入之手工装配
  • 原文地址:https://www.cnblogs.com/tszr/p/12380690.html
Copyright © 2011-2022 走看看