background image

  

PHP 片段四种表示形式。

标准 tags:<?php           ?>
short tags:<?              ?> 需要在 php.ini 中设置 short _open_tag=on,默认是 on
asp tags  

: <%             %>需要在 php.ini 中设置 asp_tags=on,默认是 off

script tags:<script language=”php”></script>
2   

PHP 变量及数据类型

1)        $variable  ,变量以字母、_开始,不能有空格
2)        赋值$variable=value;
3)        弱类型,直接赋值,不需要显示声明数据类型
4)        基本数据类型:Integer,Double,String,Boolean,Object(对象或类),Array(数组)
5)        特殊数据类型:Resourse(对第三方资源(如数据库)的引用),Null(空,未初始化的变

量)
3   

操作符

1)        赋值操作符:=
2)        算术操作符:+,-,*,/,%(取模)
3)        连接操作符:. ,无论操作数是什么,都当成 String,结果返回 String
4)        Combined Assignment Operators 合计赋值操作符:+=,*=,/=,-=,%=,.=
5)        Automatically Incrementing and Decrementing 自动增减操作符:

(1)$variable+=1 <=>$variable++;$variable-=1 <=>$variable-,跟 c 语言一样,先做其他

操作,后++或-

(2)++$variable,-$variable,先++或-,再做其他操作
6)        比较操作符:= =(左边等于右边),!=(左边不等于右边),= = =(左边等于右边,且

数据类型相同),>=,>,<,<=
7)        逻辑操作符:|| ó or,&&óand,xor(当左右两边有且只有一个是 true,返回 true),!
4   

注释:

单行注释:// ,#

多行注释:/*  */
5   

每个语句以;号结尾,与 java 相同

6   

定义常量:define(“CONSTANS_NAME”,value)

7   

打印语句:print,与 c 语言相同

8   

流程控制语句

1)        if 语句:

(1)if(expression)

{
//code to excute if expression evaluates to true

}

(2)if(expression)
{

}
else

{
}

(3)if(expression1)
{

}
elseif(expression2)

{
}

else
{

}
2)        swich 语句
switch ( expression )

{
case result

// execute this if expression results in result1
break;

case result
// execute this if expression results in result2

break;
default: