php 基础笔记 logic statements
/***************************by
garcon1986********************************/
<?php
//if 语句
$a = $b = 3;
if($a = $b)
print "a is equal to b<br>";
//else 语句
if($a < $b){
print "a is smaller than b";
} else {
print "a is not smaller than b<br>";
}
//elseif = else if 语句
if($a>$b){
print "a is bigger than b";
}else if($a = $b){
print "a is equal than b";
}else {
print "a is smaller to b<br>";
}
// when you don't use "{}", you can't separate elseif.
//当不用{}时,elseif不能分开
if($a>$b):
print "a>b";
elseif($a==$b):
//else if($a==$b): // this is wrong
print "a=b";
print '<br>';
endif;
//while语句
$i = 0;
while($i<=10){
print $i++.'<br>';
}
$i=15;
while($i<=20):
print $i;
$i++;
endwhile;
print '<br>';
//The difference between 'do while' and 'while' is: 'do while' will execute once at least.
//do while 和while的区别在于前者至少要执行一次
$i=0;
do {
echo $i;
}while($i>0);
echo '<p>';
//do while example 2
do {
if ($i < 5) {
echo "i is not big enough";
break;
}
$i *= 2;
if ($i < 50) {
break;
}
echo "i is ok";
/* process i */
} while (0);
//for(expression1; expression2; expression3) statement语句
//example1
for($i=0;$i<=6;$i++){
print $i;
}
echo '<br>';
//example2
for($i=0; ; $i++){
if($i>10){
break;
}
print $i;
}
echo '<br>';
//example3
for($i=0;;){
print $i;
$i++;
if($i>6){
break;
}
}
echo '<br>';
//example4
$i=0;
for(;;){
if($i>6){
break;
}
print $i;
$i++;
}
echo '<br>';
//example5
for($i=0;$i<=10;print $i, $i++);
echo '<p>';
//foreach语句
//example1
$arr = array('s','j','g','w','l');
foreach($arr as $value){
echo "$value<br>"; //$value is user-defined.
}
unset($value);
//list to replace foreach, same result
//使
相关文档:
原文链接:http://www.phpdo.net/index.php/2010/02/09/1-12/
PHP的数据类型的转换有两种方法可以办到:直接输入目标的数据类型和通过settype函数实现。
PHP数据转换成整数
Float型数据转换成int型
Float型转换成int型,小数点后的数将被舍弃。如果float数超贵超过了整型的取值范围,那么结果可能是0或者是整形的最小负 ......
原文链接:http://www.phpdo.net/index.php/2010/02/10/1-13/
PHP中一个基本的脚本由两部分组成:主程序和函数。
函数不仅可以构成一个PHP脚本的基本功能,也使得程序结构化,有助于程序代码的重用。
PHP函数的调用
通过按照函数格式写出函数以及相应的参数即可,衣语法如下:
String substr(string str,int start) ......
5.关于表单刷新
问:为什么我在点击浏览器的后退按钮后,所有字段的信息都被清空了?
答:这是由于你在你的表单提交页面中使用了 session_start 函数。该函数会强制当前页面不被缓存。解决办法为,在你的 Session_start 函数后加入 header("Cache-control: private"); 注意在本行之前你的PHP程序不能有任何输出。
补充: ......