例子:求阴影面积
面向过程
$r1 = 20; $r2 = 10; $mj = 3.14*$ri*$ri-3.14*$r2*$r2; echo $mj;
面向对象
class Yuan { private $r; function __construct($r) { $this->r = $r } function Mj() { return 3.14*$this->r*$this->r; } } $yuan1 = new Yuan(20); $yuan2 = new Yuan(10); eho $yuan1->Mj()-$yuan2->Mj();