PHP Class 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 ";?>