PHP采用的是C語言的語法,但是也有一些區(qū)別。“$”在php中是用于定義變量或者對象的一種符號,“$”的使用方法是:“$”加上符合php變量名定義的字符串組成一個變量。
例如:
class Test { private $a; //定義變量 public function foo1(){ return $this->a; } public function foo2(){ return $this->a; } }
$test = new Test; echo $test->foo1();
Test是個類名,不用加$符號;$a是一個私有變量,一般是有$與字符串組成;foo1與foo2是兩個成員變量,不用加$符號;$test是一個對象,必須加$符號。
推薦教程:《PHP教程》