PHP Class 5 automatic type conversion and Process Control

Source: Internet
Author: User
Tags echo date

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.