Title1

Title2

Title3

5-1 if else ifelse 邏輯判斷語句 範例

  1. 5_1.php
    <?php
    echo "<meta charset='utf-8'>";
    $a=5;
    $b=15;
    echo "\$a={$a}"."<br>";
    echo "\$b={$b}"."<br>";
    
    if($b>$a)echo '$b>$a';
    

     

  2. 5_2.php
    <?php
    echo "<meta charset='utf-8'>";
    $a=25;
    $b=15;
    echo "\$a={$a}"."<br>";
    echo "\$b={$b}"."<br>";
    
    if($b>$a){
      echo '$b>$a';
    }else{
    
      echo '$a>$b';
    }
    

     

  3. 5_3.php
    <?php
    echo "<meta charset='utf-8'>";
    $a=15;
    $b=15;
    echo "\$a={$a}"."<br>";
    echo "\$b={$b}"."<br>";
    
    if($b>$a){
      echo '$b > $a';
    }elseif($b<$a){
      echo '$b < $a';
    }else{
      echo '$b = $a';
    }
    

     

  4. 5_4.php
    <?php
    echo "<meta charset='utf-8'>";
    $a=15;
    $b=25;
    echo "\$a={$a}"."<br>";
    echo "\$b={$b}"."<br>";
    
    $msg=($a >= $b)?'$a >= $b':'$a < $b';
    echo $msg;