<?8,函数默认值。PHP中函数支持设定默认值,与C++风格相同。
//方法一:
function foo(&$bar){
$bar.=" and something extra";
}
$str="This is a String,";
foo($str);
echo $str; //output:This is a String, and something extra
echo "<br>";
//方法二:
function foo1($bar){
$bar.=" and something extra";
}
$str="This is a String,";
foo1($str);
echo $str; //output:This is a String,
echo "<br>";
foo1(&$str);
echo $str; //output:This is a String, and something extra
?>
<?9,PHP的几个特殊符号意义。
function makecoffee($type="coffee"){
echo "making a cup of $type.\n";
}
echo makecoffee(); //"making a cup of coffee"
echo makecoffee("espresso"); //"making a cup of espresso"
/*
注意:当使用参数默认值时所有有默认值的参数应该在无默认值的参数的后边定义。否则,程序将不会按照所想的工作。
*/
function test($type="test",$ff){ //错误示例
return $type.$ff;
}
$ 变量
& 变量的地址(加在变量前)
@ 不显示错误信息(加在变量前)
-> 类的方法或者属性
=> 数组的元素值
?: 三元运算子
10,include()语句与require()语句
如果要根据条件或循环包含文件,需要使用include().
require()语句只是被简单的包含一次,任何的条件语句或循环等对其无效。
由于include()是一个特殊的语句结构,因此若语句在一个语句块中,则必须把他包含在一个语句块中。
<?
//下面为错误语句
if($condition)
include($file);
else
include($other);
//下面为正确语句
if($condition){
include($file);
}else
{
include($other);
}
?>