一、自定義函數
function add($a,$b){
$c=$a+$b;
echo 'add test:';
echo $c;
return $c;
}
add(1,2);
輸出結果:
add test:3
二、調用類裡面函數
1、雙冒號::,不用實例化,直接類名調用
class test{
public function add($a,$b){
$c=$a+$b;
echo 'class test:';
echo $c;
return $c;
}
}
test::add(1,2);
2、->,實例化後的對象使用
class test{
public function add($a,$b){
$c=$a+$b;
echo 'class test:';
echo $c;
return $c;
}
}
$object=new test();
$object->add(1,3);