PHP Flow Control if Almost identical to C
- Slides: 14
PHP Flow Control
if Almost identical to C <? php if ($int. M > $int. G){ echo “<p>$int. M is greater</p>”; } ? >
If else Almost identical to C <? php if ($int. M > $int. G){ echo “<p>$int. M is greater</p>”; } else { echo “<p>$int. G is greater</p>”; } ? >
If elseif else PHP <? php if ($int. M > $int. G){ echo “<p>$int. M is greater</p>”; } elseif ( $int. M < $int. G) { echo “<p>$int. G is greater</p>”; } else { echo “<p>$int. G is equal to $int. M</p>”; } ? >
switch ($str. A) { case “Russell”: echo “<p> Hi Russell </p>”; break; case “Kevin”: echo “<p> Hi Kevin</p>”; break; case “Dug”: echo “<p> Hi Dug</p>”; break; default: echo “<p> I don't know you. . . </p>”; }
while $int. A = 0; while ($int. A < 11) { echo "<p>now the value of ". '$int. A'. " is $int. A</p>"; $int. A++; } Notice the use of “ and ' The first $int. A in the echo statement does not get a numerical value. . .
do-while do { echo"<p>now the value of ". '$int. A'. " is $int. A</p>"; $int. A++; } while ($int. A < 21);
for loops Similar to C: e. g. , for ($int. A = 1; $int. A <=10; $int. A++) {. . . }
foreach (first form) Also a special construct: foreach (array as value) statement $arr. Num = array (0=>"zero", 1=>"one", 2=>"two", 4=>"four", 3=>"three", 5 =>"five"); $int. Count = 0; foreach($arr. Num as $str. Num){ echo "<p>". $int. Count++. "$str. Num</p>"; }
foreach (second form) foreach (array as key=> value) statement $arr. Num = array (0=>"zero", 1=>"one", 2=>"two", 4=>"four", 3=>"three", 5 =>"five"); $int. Count = 0; foreach($arr. Num as $int. Key=>$str. Num){ echo "<p> $int. Key $str. Num</p>"; }
foreach (second form) foreach (array as key=> value) statement Non-numerical keys $arr. Num = array ("0"=>"zero", "1"=>"one", "2"=>"two", "4"=>"four", "3"=>" three", "5"=>"five"); $int. Count = 0; foreach($arr. Num as $str. Key=>$str. Num){ echo "<p> $str. Key $str. Num</p>"; }
break $int. A = 1; while (1) { //do something $int. A++; if ($int. A > 10) break; }
continue for($int. A=1; $int. A<10; $int. A++){ if($int. A % 2){continue; } echo "<p>print even number } $int. A</p>";
Demo • Easy. PHP • GET • POST • REQUEST • Superglobals • File manipulations
- Identical by descent vs identical by state
- Flow control functions in php
- Data flow vs control flow
- Control flow and data flow computers
- Control flow vs transaction flow
- Php/index.php?id=
- Php php://input
- Stock control e flow control
- Flow control and error control
- Control structures in php
- Control structures in php
- Magic box respiratory
- Venturi mask flow rate
- O2 mask types
- Turbulent flow definition