PHP class 5 automatic type conversion and process control. PHP fifth course automatic type conversion and process control Learning Overview: 1. learn about automatic type conversion 2. understand basic process control statements. 3. example: achieve automatic writing of calendar tables type PHP lesson 5 automatic type conversion and process control
Learning Overview:
1. learn about automatic type conversion
2. understand basic process control statements
3. example: compile a calendar table
Automatic type conversion
1) convert integer to string
echo $num."abc";
2) convert string to integer
$ Str + 3;
3) convert to Boolean type
False: 0 "" 0 "false array () null undefined
4) forced type conversion
(int)$str(float)$str(string)$str
5) constants
define("HOST","localhost");
6) operators
① RMB
++ --
② Binary
=-*/%
= + =-= * =/= % =
>>=<==! ===! =
& |!
③ Ternary
? :
Process control:
1. Process control
2. Functions
Process control:
I. branch structure
If... elseif... else
Switch... case
If the condition is a fixed value, use the switch statement.
II. loop control
For
While
3. abort a loop
Break: end directly
";}}?>//1 2
Continue: end this cycle
";}}?>//1 2 4 5 6 7 8 9
Tip: exit indicates that the following program is suspended.
Echo date ("w"); w in date indicates the day of the week
5. remaining parts
1. do... while
=60);?>
4. multiplication table
"; }?>
3. implement calendar tables in PHP
Calendar table:
1. two-layer for loop
2. line-by-line color change
3. if condition judgment
4. encode the header
";for($i=1;$i<=$days;){echo "";for($j=0;$j<7;$j++){if($i>$days){echo " ";} else{echo "{$i}";}$i++;}echo "";}echo "";?>
Add background color
"; For ($ I = 1; $ I <= $ days;) {$ k ++; if ($ k % 2 = 1) {echo"";} Else {echo"";}For ($ j = 0; $ j <7; $ j ++) {if ($ I >$ days) {echo" ";} Else {echo"{$ I}";}$ I ++;} echo"";} Echo"";?> Abort script 2. exit (); abort the script using 3.die ();
"; Die (" Stop the script from here "); echo" 2222222 ";?>
And process control Learning Overview: 1. learn about automatic type conversion 2. learn about basic process control statements 3. example: implement automatic type writing for calendar tables...