一、自定义函数

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);
05-11 10:54
查看更多