//定义继承于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
<?php
$fruit = ('apple' => '苹果’, 'banana' => '香蕉', 'pineapple' => '菠萝');
foreach ($fruit as $key => $value)
{
echo '<br>数组fruit中键为'.$key.'的值是'.$value;
}
?>
$fruit = ('apple' => '苹果’, 'banana' => '香蕉', 'pineapple' => '菠萝');
foreach ($fruit as $key => $value)
{
echo '<br>数组fruit中键为'.$key.'的值是'.$value;
}
?>
2014-12-08
第一种;
$arr = array('apple' => '苹果');
第二种;
$arr = array();
$arr['apple'] = '苹果';
$arr = array('apple' => '苹果');
第二种;
$arr = array();
$arr['apple'] = '苹果';
2014-12-08
<?php
$fruit = array('apple', 'banana', 'pineapple');
foreach ($fruit as $key => $value)
{
echo '<br>第'.$key.'个值是:'.$value;
}
?>
$fruit = array('apple', 'banana', 'pineapple');
foreach ($fruit as $key => $value)
{
echo '<br>第'.$key.'个值是:'.$value;
}
?>
2014-12-08
<?php
$fruit = arr('苹果', ’香蕉', '菠萝');
for ($index=1; $index<3; $index++)
{
echo '<br>数字第'.$index.'个值是:'.$fruit[$index];
}
?>
$fruit = arr('苹果', ’香蕉', '菠萝');
for ($index=1; $index<3; $index++)
{
echo '<br>数字第'.$index.'个值是:'.$fruit[$index];
}
?>
2014-12-08
第一种:
$arr = array();
$arr[0] = '苹果';
第二种:
$arr = array('0' => '苹果');
第三种:
$arr = array('苹果');
$arr = array();
$arr[0] = '苹果';
第二种:
$arr = array('0' => '苹果');
第三种:
$arr = array('苹果');
2014-12-08