php learns the flow control implementation code

  • 2020-05-07 19:20:18
  • OfStack

 
<?php 
/* 
*  Process control  
* 
* 1.  Sequential structure  
* 2.  Branching structure -- Conditions of structure -- Choose structure  
* 1. Single road branch  
* // conditions bool,true or false,> < == !- & || ! 
* if( conditions ) 
*  Do the following 1 statement  
* if( conditions ) 
* { 
*  Code segment ; 
*  Code segment ; 
* } 
* 
* 2. Double road branch  
*  use else clause  
* 
* if( conditions ) 
*  perform 1 statement  
* else 
*  perform 1 statement  
* if( conditions ){ 
* 1 One or more codes  
* }else{ 
* 1 One or more codes  
* } 
* 
* 3. Multiple branch  
*  You can use  if else if  and  switch case 
* // This is a 1 It's kind of mutually exclusive  
* if( conditions ){ 
* 
* }else if( conditions ){ 
* }else if( conditions ){ 
* }else{ 
* } 
* 4. Nested branches  
* if(){ 
* if(){ 
* }else{ 
* if(){} 
* } 
* } 
* 3.  Loop structure  
* 
* 
* 
* 
* 
*  Conclusion:  
*  If it's judgment 1 Section of the range   Use the elseif 
*  Used if it is a single match switch case 
*/ 
// One way to perform  
$a=10; 
$b=5; 
if($a > $b) 
echo "$a  Is greater than  $b  the "; 
// Dual executive  
$a=10; 
$b=20; 
if($a>$b) 
{ 
echo "$a  Is greater than  $b</br>"; 
} 
else 
{ 
echo "$a  Less than  $b</br>"; 
} 
// Multiple execution  
$hour=date("H"); 
if($hour > 6 && $hour < 9) 
{ 
echo "good morning!": 
} 
else if($hour > 9 && $hour < 12) 
{ 
echo " Good morning "; 
} 
else if($hour > 12 && $hour < 14) 
{ 
echo " good afternoon "; 
} 
else if($hour > 14 && $hour < 17) 
{ 
echo " Good afternoon, "; 
} 
else if($hour > 17 && $hour < 19) 
{ 
echo " Good evening "; 
} 
else if($hour > 19 && $hour <22) 
{ 
echo " Good evening "; 
} 
else 
{ 
echo " Good night, "; 
} 
// Improve code based on mutual exclusion  
$hour=date("H"); 
if($hour < 9) 
{ 
echo "good morning!": 
} 
else if($hour < 12) 
{ 
echo " Good morning "; 
} 
else if($hour < 14) 
{ 
echo case " Mon": 
echo " week 1"; 
break;" good afternoon "; 
} 
else if($hour < 17) 
{ 
echo " Good afternoon, "; 
} 
else if($hour > 19) 
{ 
echo " Good evening "; 
} 
else if($hour < 22) 
{ 
echo " Good evening "; 
} 
else 
{ 
echo " Good night, "; 
} 
// Judge the day  
$week=date("D");// Get the day of the week  
switch($week) //switch( variable )  Variables use only integers and strings  
{ 
case "Mon": 
echo " week 1"; 
break; 
case "Tue" 
echo " week 2"; 
break; 
case "Wed": 
echo " week 3"; 
break; 
case "Thu": 
echo " week 4"; 
break; 
case "Fri": 
echo " week 5"; 
break; 
default: 
echo " Over the weekend "; 
} 
// Nested classes  
$sex=$_GET["sex"]; 
$age=$_GET["age"]; 
if($sex=="nan") 
{ 
if($age >= 60) 
{ 
echo " this $sex  retired ".($age-60)." years "; 
} 
else 
{ 
echo " The man is still at work ".(60-$age)." Years before retirement "; 
} 
} 
else 
{ 
if($age >= 66) 
{ 
echo " this $sex  retired ".($age-66)." years "; 
} 
else 
{ 
echo " This lady is still at work ".(66-$age)." Years before retirement "; 
} 
} 
?> 

Related articles: