PHP 学习1.2
1. 流程控制
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义和调用函数</title>
</head>
<body>
<?
$a=5;
$b=6;
$c=5;
$i=0;
$arr = array("one", "two", "three");
if($a>$b){
echo '$a bigger than $b ';
}elseif($a==$c){
echo '$a equal to $b ' ;
}
else{
echo '$a smaller than $b';
}
while($i<$b){
print '<br/>Number:'.$i;
$i++;
}
do{
$i=0;
echo '<br/>do while control';
}
while($i);
for($i=0;$i<$a;$i++){
if($i==3){
echo '<br/> for control:the current value= '.$i.'<br />';
break;
}
}
while (list($key, $value) = each($arr)) {
echo "Key: $key; Value: $value<br />\n";
}
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value<br />";
}
for($i=0;$i<$a;$i++){
echo "i= $i<br />";
for($j=0;$j<2;$j++){
if($j==1){
continue;
}
echo "j = $j <br />";
}
break;
}
switch($a){
case 5:
echo 'switch is 5<br/>';
break;
case 'lin.su':
echo 'switch is string 5';
break;
}
require 'index.php';
include 'phpinfo.php';
echo gettype($cn); //phpinfo variable $cn
?>
</body>
</html>
备注:""里面的$a就表示变量 '' 里面就表示字符串了, 版本5++