Home > Backend Development > PHP Tutorial > PHP Lesson 5 Automatic Type Conversion and Process Control_PHP Tutorial

PHP Lesson 5 Automatic Type Conversion and Process Control_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:19:48
Original
888 people have browsed it

PHP Lesson 5 Automatic Type Conversion and Process Control

Learning Summary:

1. Understand what automatic type conversion is

2. Understand basic flow control statements

3. Example: How to write a calendar table


Automatic type conversion

1) Convert integer to string
echo $num."abc";
Copy after login


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


4) Forced type conversion
(int)$str
(float)$str
(string)$str
Copy after login




5)Constant
define("HOST","localhost");
Copy after login

6)Operator
①One yuan
++ --


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


③Three yuan
? :


Process Control:
1. Process control
2. Function




Process control:


1. Branch structure
if...elseif....else
switch...case
If the condition is a fixed value, use the switch statement


2. Loop control
for
while


3. Abort the loop
break: end directly
<?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
Copy after login


continue: End this loop
<?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
Copy after login




Tips: exit means suspending the following program
echo date("w");
date 中w表示星期几
<?PHP
 	header("content-type:text/html;charset=utf-8");
	echo date("Y-M-D");//分别表示年月日
	exit;
	echo "John";
	?>
Copy after login

5. The remaining part
1.do...while

				<?php
		 
		 	$score=31;
			do{
				echo "<h1>{$score}</h1>";
			}while($score>=60);
		?>
Copy after login



4. Multiplication table
<?php
		    for($i=1;$i<=9;$i++){
		    	for($j=1;$j<=$i;$j++){
		    		echo "$i*$j=".$i*$j." ";
		    	}
		    	echo "<br>";
		    }
	?>
Copy after login



3. PHP implements calendar table


Calendar form:
1. Two-layer for loop
2. Change colors every other row
3. Use if conditional judgment
4.Change the header encoding

<?php
  header("content-type:text/html;charset=utf-8");
	$days= 31;
	
	echo "<table width=&#39;700px&#39; border=&#39;1px&#39;>";
	for($i=1;$i<=$days;){
		echo "<tr>";
		for($j=0;$j<7;$j++){
			if($i>$days){
				echo "<td>&#160;</td>";
			} else{
			echo "<td>{$i}</td>";
			}
				$i++;
		}
		echo "</tr>";
		
	}
	
	echo "</table>";
?>
Copy after login

Add background color


<?php
  header("content-type:text/html;charset=utf-8");
	$days= 31;
	
	echo "<table width=&#39;700px&#39; border=&#39;1px&#39;>";
	for($i=1;$i<=$days;){
		
		$k++;
		
		if($k%2==1){
			echo "<tr bgcolor=&#39;#cccccc&#39;>";
		}else{
			echo "<tr>";
		}
		
		for($j=0;$j<7;$j++){
			if($i>$days){
				echo "<td>&#160;</td>";
			} else{
			echo "<td>{$i}</td>";
			}
				$i++;
		}
		echo "</tr>";
		
	}
	
	echo "</table>";
?>
	中止脚本
	
		2.exit();中止脚本使用
	    3.die();
			    <?php
		 
		 echo "11111<br>";
		 die("从这儿开始脚本中止");
		 echo "2222222";
		?>
Copy after login


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871184.htmlTechArticlePHP Lesson 5 Automatic Type Conversion and Process Control Learning Summary: 1. Understand what automatic type conversion is 2. Understand basic flow control statements 3. Example: Implement automatic type writing of calendar tables...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template