<?
//方法一:
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
?>
8,函数默认值。PHP中函数支持设定默认值,与C++风格相同。
<?
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;
}
9,PHP的几个特殊符号意义。