<?php
class Car {
public $name1 = '汽车';
public $name2 = '摩托车';
public function getName ()
{
return $this->name2;
}
}
$car = new Car();
echo $car->name1."\n";
echo $car->getName()."\n";
?>
class Car {
public $name1 = '汽车';
public $name2 = '摩托车';
public function getName ()
{
return $this->name2;
}
}
$car = new Car();
echo $car->name1."\n";
echo $car->getName()."\n";
?>
2014-12-10
$arr = array('Hello', 'World!');
$result = implode('', $arr);
print_r($result);//结果显示Hello World!
结果为,HelloWorld!而非Hello World!
$result = implode('', $arr);
print_r($result);//结果显示Hello World!
结果为,HelloWorld!而非Hello World!
2014-12-09
<?php
class Car {
var $name = '汽车';
function getName() {
return $this->name;
}
}
$car = new Car();
$car->name = '奥迪A6';
echo $car->getname;
class Car {
var $name = '汽车';
function getName() {
return $this->name;
}
}
$car = new Car();
$car->name = '奥迪A6';
echo $car->getname;
2014-12-09
//定义继承于Car的Truck类
class Truck extends Car{
public function getSpeed(){
$this->speed += 10;
}
public function speedUp(){
return $this->speed += 50;
}
}
$car = new Truck();
$car->getSpeed();//获得现有的速度
$car->speedUp(); //加速
echo $car->speed;
class Truck extends Car{
public function getSpeed(){
$this->speed += 10;
}
public function speedUp(){
return $this->speed += 50;
}
}
$car = new Truck();
$car->getSpeed();//获得现有的速度
$car->speedUp(); //加速
echo $car->speed;
2014-12-09
<?php
class Car {
public $speed = 0; //汽车的起始速度是0
public function speedUp() {
$this->speed += 10;
return $this->speed;
}
public function getSpeed(){
return $this->speed;
}
}
class Car {
public $speed = 0; //汽车的起始速度是0
public function speedUp() {
$this->speed += 10;
return $this->speed;
}
public function getSpeed(){
return $this->speed;
}
}
2014-12-09