Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP Flow Control. if Almost identical to C <?php if ($intM > $intG){ echo “ $intM is greater ”; } ?>

Similar presentations


Presentation on theme: "PHP Flow Control. if Almost identical to C <?php if ($intM > $intG){ echo “ $intM is greater ”; } ?>"— Presentation transcript:

1 PHP Flow Control

2 if Almost identical to C <?php if ($intM > $intG){ echo “ $intM is greater ”; } ?>

3 If else Almost identical to C <?php if ($intM > $intG){ echo “ $intM is greater ”; } else { echo “ $intG is greater ”; } ?>

4 If elseif else PHP <?php if ($intM > $intG){ echo “ $intM is greater ”; } elseif ( $intM < $intG) { echo “ $intG is greater ”; } else { echo “ $intG is equal to $intM ”; } ?>

5 switch switch ($strA) { case “Russell”: echo “ Hi Russell ”; break; case “Kevin”: echo “ Hi Kevin ”; break; case “Dug”: echo “ Hi Dug ”; break; default: echo “ I don't know you... ”; }

6 while $intA = 0; while ($intA < 11) { echo " now the value of ". '$intA'. " is $intA "; $intA++; } ' Notice the use of “ and ' The first $intA in the echo statement does not get a numerical value...

7 do-while do { echo" now the value of ". '$intA'. " is $intA "; $intA++; } while ($intA < 21);

8 for loops Similar to C:  e.g., for ($intA = 1; $intA <=10; $intA++) {... }

9 foreach (first form) Also a special construct: foreach (array as value) foreach (array as value) statement $arrNum = array (0=>"zero", 1=>"one",2=>"two",4=>"four",3=>"three",5 =>"five"); $intCount = 0; foreach($arrNum as $strNum){ echo " ". $intCount++. "$strNum "; }

10 foreach (second form) foreach (array as key=> value) foreach (array as key=> value) statement $arrNum = array (0=>"zero", 1=>"one",2=>"two",4=>"four",3=>"three",5 =>"five"); $intCount = 0; foreach($arrNum as $intKey=>$strNum){ echo " $intKey $strNum "; }

11 foreach (second form) foreach (array as key=> value) foreach (array as key=> value) statement Non-numerical keys $arrNum = array ("0"=>"zero", "1"=>"one","2"=>"two","4"=>"four","3"=>" three","5"=>"five"); $intCount = 0; foreach($arrNum as $strKey=>$strNum){ echo " $strKey $strNum "; }

12 break $intA = 1; while (1) { //do something $intA++; if ($intA > 10) break; }

13 continue for($intA=1; $intA<10; $intA++){ if($intA % 2){continue;} echo " print even number $intA "; }

14 Demo EasyPHP GET POST REQUEST Superglobals File manipulations


Download ppt "PHP Flow Control. if Almost identical to C <?php if ($intM > $intG){ echo “ $intM is greater ”; } ?>"

Similar presentations


Ads by Google