PHP class fifth automatic type conversion and Process Control

Source: Internet
Author: User
Tags echo date php class

Study Summary:

1. Understand what automatic type conversions are

2. Understanding Basic Process Control Statements

3. Example: Implementing a Calendar Table


Automatic type conversion

1) integer-to-string
echo $num. " ABC ";


2) string-to-integer
$str +3;
3) Turn Boolean type
False case 0 "" "0" false array () NULL undefined


4) Forced type conversion
(int) $str (float) $str (string) $str




5) Constants
Define ("HOST", "localhost");

6) operator
① One Dollar
++ --


② two Yuan
= - *  / %
= += -= *= /= %=
> >= < <= = = = = = = = =!==
&& | | !


③ Sanyuan
? :


Process Control:
1. Process Control
2. Functions




Process Control:


I. Branching structure
If...elseif....else
Switch...case
If the condition is a fixed value, use the switch statement


Two. Cycle control
For
While


Three. Abort the loop
Break: Direct End
<? PHP header ("Content-type:text/html;charset=utf-8"), for ($i =1, $i <10; $i + +) {if ($i ==3) {break;} Else{echo $i. " <br> ";}}? >//1 2


Continue: End of this cycle
<? PHP header ("Content-type:text/html;charset=utf-8"), for ($i =1, $i <10; $i + +) {if ($i ==3) {continue;} Else{echo $i. " <br> ";}}? >//1 2 4 5 6 7 8 9




Tip: Exit means pause the following program
Echo Date ("W");d ate in W for the day of the week < PHP header ("Content-type:text/html;charset=utf-8"), Echo date ("y-m-d"), or//Exit;echo "John" for the month and day respectively; >

Five. Remaining parts
1.do...while

<?php  $score =31;do{echo "



4.99 Multiplication Table
<?php for    ($i =1; $i <=9; $i + +) {for    ($j =1; $j <= $i; $j + +) {    echo "$i * $j =". $i * $j. " ";    }    echo "<br>";    }? >



3.PHP Implementation Calendar Table


Calendar table:
1. Two-layer for loop
2. Interlaced color change
3. Use the IF condition to judge
4.header Head Change Code

<?php  Header ("Content-type:text/html;charset=utf-8"); $days = 31;echo "<table width= ' 700px ' border= ' 1px ' > "for ($i =1, $i <= $days;) {echo" <tr> "; for ($j =0; $j <7; $j + +) {if ($i > $days) {echo" <td> </td > ";} Else{echo "<td>{$i}</td>";} $i + +;} echo "</tr>";} echo "</table>";? >

Add a background color


<?php  Header ("Content-type:text/html;charset=utf-8"); $days = 31;echo "<table width= ' 700px ' border= ' 1px ' > "for ($i =1; $i <= $days;) {$k ++;if ($k%2==1) {echo" <tr bgcolor= ' #cccccc ' > ";} Else{echo "<tr>";} for ($j =0; $j <7; $j + +) {if ($i > $days) {echo "<td> </td>";} else{echo "<td>{$i}</td>";} $i + +;} echo "</tr>";} echo "</table>";? > Abort Script 2.exit (); Abort script using    3.die ();    <?php  echo "11111<br>"; die ("Start script abort from here"); echo "2222222";? >


PHP class fifth automatic type conversion and Process Control

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.