Three process control structures of the program
1. Ordered structure
2. Select a structure
3. Loop structure
The result is as follows:
The code is as follows: |
Copy code |
$ D = date ("D "); If ($ d = "Tue ") Echo "Today is Tuesday "; Else Echo "today is not Tuesday "; ?>
|
The array can be used to determine the day of the week.
The execution result should be as follows:
The code is as follows: |
Copy code |
$ Srttime = date ("w", time ()); $ Array = array ('day', 'yi', '2', '3', '4', '5', '6 '); $ Todaytime = date ("Y, m, d, week {$ array [$ srttime]}", time ()); Echo $ todaytime; ?> |
1. if (condition 1 ){
? Why? /P>
}
<HTML>
<HEAD>
<TITLE> IF-1 </TITLE>
</HEAD>
<BODY>
<?
$ A = 100;
If ($ a == 100 ){
Echo "A is 100 .";
}
?>
</BODY>
</HTML>
Or
If (condition 1 ){
? Why? /P>
} Else {
? Too many? /P>
}
<HTML>
<HEAD>
<TITLE> IF... ELSE-1 </TITLE>
</HEAD>
<BODY>
<?
$ A = 120;
If ($ a <100 ){
Echo "A was small than 100 .";
}
Else {
Echo "A was big than 100 .";
}
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> IF... ELSE-2 </TITLE>
</HEAD>
<BODY>
<?
$ File = "files.txt ";
If (file_exists ($ file )){//? Z query? N case?
Echo "? Yes? N case of files.txt? Hot? <BR> ";
Readfile ($ file );//? Outbound? N case? Hot? Br/>}
Else {
Echo "? O here? N case <BR> ";
}
?>
</BODY>
</HTML>
Or
If (condition 1 ){
? Why? /P>
} Elseif {
? Too many? /P>
} Elseif {
? Too many? /P>
}
...........
Else {
? Why?
}
<HTML>
<HEAD>
<TITLE> IF... ELSEIF... ELSE-1 </TITLE>
</HEAD>
<BODY>
<?
$ A = 100;
$ B = 200;
If ($ a> $ B ){
Echo "a is bigger than B ";
} Elseif ($ a ==$ B ){
Echo "a is equal to B ";
} Else {
Print "a is smaller than B ";
}
?>
</BODY>
</HTML>
2. while (condition 1) {// condition? Why? ??
? Why? /P>
}
<HTML>
<HEAD>
<TITLE> WHILE </TITLE>
</HEAD>
<BODY>
<?
$ A = 1;
While ($ a <10 ){
Echo "$ a <BR> ";
$ A ++;
}
?>
</BODY>
</HTML>
3. do {
? Why? /P>
} While (condition); // condition? Why? ??
<HTML>
<HEAD>
<TITLE> Do... WHILE-1 </TITLE>
</HEAD>
<BODY>
<?
$ A = 1;
Do {
Echo "$ a <BR> ";
$ A ++;
} While ($ a <10)
?>
</BODY>
</HTML>
4. for (initial condition; criterion? Too many? Condition change ?? Why? {
? Why? /P>
}
<HTML>
<HEAD>
<TITLE> For-1 </TITLE>
</HEAD>
<BODY>
<?
For ($ a = 1; $ a <10; $ a ++)
{
Echo "$ a <BR> ";
}
?>
</BODY>
</HTML>
5. break? Why? Too many? Circle
<HTML>
<HEAD>
<TITLE> BREAK </TITLE>
</HEAD>
<BODY>
<?
$ Abc [0] = '0 ';
$ Abc [1] = '1 ';
$ Abc [2] = '2 ';
$ A = 0;
While ($ a <4)
{
If ($ abc [$ a] = '2') {// if? Why? Hop? While ()? Circle
Break;
}
Echo "$ ";
$ A ++;
}
?>
</BODY>
</HTML>
6. continue // medium? Why? Too many? Circle, jump? Circle ???? Next time
<HTML>
<HEAD>
<TITLE> CONTINUE </TITLE>
</HEAD>
<BODY>
<?
For ($ I = 10; $ I> 1; $ I --){
If ($ I = 2) {// if? Why? ? ? For ()? Circle ,?? Next ()? Circle
Continue;
}
Echo "$ I <br> ";
}
?>
</BODY>
</HTML>
7. switch (condition ){
Case 'case value 1 ':
? Why? Nbsp; // condition? If the case value is the same, then? Partially? Why? It does not stop until it encounters a break.
Break;
Case 'case value 2:
? Too many? Br/> break;
............
Default:
? Why?
Break;
}
<HTML>
<HEAD>
<TITLE> SWITCH </TITLE>
</HEAD>
<BODY>
<?
Switch ($ I ){
Case 0:
Echo "I equals 0 ";
Case 1:
Echo "I equals 1 ";
Case 2:
Echo "I equals 2 ";
}
?>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> Switch-SWITCH </TITLE>
</HEAD>
<BODY>
<?
Switch ($ ){
Case '1 ':
Echo "one ";
Break;
Case '2 ':
Echo "two ";
Break;
Case '3 ':
Echo "three ";
Break;
Case '4 ':
Echo "four ";
Break;
Case '5 ':
Echo "five ";
Break;
Default:
Echo "ZERO ";
Break;
}
?>
</BODY>
</HTML>
Notes
In PHP syntax, a semicolon is added to the end of each instruction, but not to the end of part of the ending symbol.
In the process part of the separator, both use {as the part of the start, use} as the end, and C language is the same. However, C can define the beginning and end of a in statement (such as Pascal), but PHP cannot define a begin statement.