php:函数间的参数传递
1.值传递
复制代码 代码如下:
function exam($var1){
$var1++;
echo "In Exam:" . $var1 . "
";
}
$var1 = 1;
echo $var1 . "
";
exam($var1);
echo $var1 . "
";
?>
复制代码 代码如下:
function exam( &$var1){
$var1++;
echo "In Exam:" . $var1 . "
";
}
$var1 = 1;
echo $var1 . "
";
exam($var1);
echo $var1 . "
";
?>
复制代码 代码如下:
function values($price, $tax=""){
$price += $prive * $tax;
echo "Total Price:" . $price . "
";
}
values(100, 0.25);
values(100);
复制代码 代码如下:
class Obj{
public $name;
public $age;
public $gander;
public function __construct($name, $age, $gander){
$this->name = $name;
$this->age = $age;
$this->gander = $gander;
}
public function show_info(){
echo $this->name . " " . $this->age . " " . $this->gander . "
";
}
}
function grow($obj){
$obj->age++;
}
function test(){
$obj = new Obj("Mr. zhan", "12", "male");
$obj->show_info();
grow($obj);
$obj->show_info();
grow($obj);
$obj->show_info();
}
test();
?>