Automatic type conversion and flow control in the fifth lesson of PHP

Source: Internet
Author: User
Tags date exit continue echo date end header string

Study Summary:

1. Understand what automatic type conversions are

2. Understand the basic Process Control statements

3. Example: the implementation of the calendar form


Automatic type conversion

1) Integer Turn string
echo $num. " ABC ";


2) String Rounding type
$str +3;
3) Boolean type
False case 0 "" 0 "false array () NULL undefined


4) Force type conversion
(int) $str
(float) $str
(String) $str




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

6) operator
① a Dollar
++ --


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


③ Ternary
? :


Process Control:
1. Process Control
2. function




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. Discontinue circulation
Break: Direct End
 
  ";
		}
	}
		
	? >//1 2


Continue: End this cycle
 
  ";
		}
	}
		
	? >//1 2 4 5 6 7 8 9




Tip: Exit says pause the following program
Echo Date ("W");
Date in W indicates day of the week

 
  

Five. The remaining part
1.do...while

				
 
  {$score} ";
			} while ($score >=60);
		? >



4.99 Multiplication Table
 
  ";
		    }
	? >



3.PHP Implementation Calendar Table


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

 
  ";
	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 script using
	    3.die ();
			    
 
   ";
		 Die ("Start script abort from here");
		 echo "2222222";
		? >




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.