<?php
echo "filename:phptutorial4.php"."<br/>";
echo "3.tutorial:php statement and test"."<br/>";
echo "--------------------------------------------------------------------"."<br/>";
/*file :phptutorial4.php
title :php statement and test
date :03/05/2013
tool :wamp+notepad++
author:chinayaosir
blog :http://blog.csdn.net/chinayaosir
*/
/*
1.顺序语句
statement1;
statement2;
statement3;
2.条件语句[if/if...else/switch]
if (bool_expr){
statement;
}
if (bool_expr){
statement1;
}else{
statement2;
}
if (bool_expr){
statement1;
}elseif(bool_expr){
statement2;
}else{
statement3;
}
switch (val_expr){
case v1:
statement1;
break;
case v2:
statement2;
break;
default:
defautlstatement;
}
3.循环语句[while,do...while,for,foreach]和循环控制break/contiune
while (bool_expr) {
statement;
break/contiune;
}
do{
statement;
break/contiune;
}while(bool_expr)
for (initvalue; bool_expr; changevalue){
statement;
}
.foreach
foreach (array as value){
statement;
}
*/
//php statement code demo and test
//1.顺序语句
$x=10; //statement1
$y=50; //statement2
echo "x*y=".$x*$y."<br/>"; //statement3
//2.条件语句
$minno=111;
$maxno=999;
$midno=555;
if ($maxno>$midno){
echo "maxno>midno"."<br/>";//statement
}
if ($maxno>$midno){
echo "maxno>midno"."<br/>";//statement1
}else{
echo "maxno<midno"."<br/>";//statement2
}
if ($maxno>$midno){
echo "maxno>midno"."<br/>";//statement1
}elseif(bool_expr){
echo "maxno<midno"."<br/>";//statement2
}else{
echo "maxno=midno"."<br/>";//statement3
}
/*
mouse:鼠,cat:猫,dog:狗,pig:猪,
*/
$englishword="cat";
$chineseword="";
switch ($englishword){
case "cat":
$chineseword="猫";
break;
case "mouse":
$chineseword="鼠";
break;
default:
$chineseword=" ";
}
echo "$englishword=$chineseword"."<br/>";
//3.循环语句[while,do...while,for,foreach]和循环控制break/contiune
$maxi=5;
while ($maxi>=1) {
echo "maxi=$maxi,";
$maxi--;
};
echo "<br/>";
$minx=3;
do{
echo "minx=$minx";
}while($minx<3);
echo "<br/>";
$fori=0;
for ($fori=1; $fori<=5; $fori++){
echo "fori=$fori,";
}
echo "<br/>";
$shengxiao=array('猴','鸡','狗','猪','鼠','牛','虎','兔','龙','蛇','马','羊');
foreach ($shengxiao as $eachsx){
echo "$eachsx,";
}
echo "<br/>";
/*
code export value pls see below
filename:phptutorial4.php
3.tutorial:php statement and test
--------------------------------------------------------------------
x*y=500
maxno>midno
maxno>midno
maxno>midno
cat=猫
maxi=5,maxi=4,maxi=3,maxi=2,maxi=1,
minx=3
fori=1,fori=2,fori=3,fori=4,fori=5,
猴,鸡,狗,猪,鼠,牛,虎,兔,龙,蛇,马,羊,
*/
?>