本文整理汇总了PHP中Car::setStatus方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::setStatus方法的具体用法?PHP Car::setStatus怎么用?PHP Car::setStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::setStatus方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setStatus
{
return $this->status;
}
//Setter - for private - status
function setStatus($new_status)
{
$this->status = $new_status;
}
}
$car1 = new Car("2014 Porsche 911", 114991, 0, NULL, "images/porsche.jpg");
$car2 = new Car("2011 Ford F450", 55995, 0, NULL, "images/ford.jpg");
$car3 = new Car("2013 Lexus RX 350", 44700, 0, NULL, "images/lexus.jpg");
$car4 = new Car("Mercedes Benz CLS550", 39900, 37979, NULL, "images/mercedes.jpg");
$car5 = new Car("Ford F150", 24900, 45979, NULL, "images/f150.jpg");
// error testing: var_dump("Car 4 status " . $car4->getStatus());
$car4->setStatus("used");
// error testing: var_dump("Car 4 status " . $car4->getStatus());
$cars = array($car1, $car2, $car3, $car4, $car5);
$cars_matching_search = array();
foreach ($cars as $car) {
if ($car->getPrice() < $_GET["price"]) {
array_push($cars_matching_search, $car);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Your Car Dealership's Homepage</title>
示例2: setStatus
// all objects in PHP are based on classes
class Car
{
// variables inside a class are called properties or attributes
public $make = null;
public $model = null;
public $color = null;
protected $status = 'off';
// functions inside a class are called methods
public function setStatus($value)
{
// '$this' refers to the current instance
$this->status = $value;
}
public function getStatus()
{
return $this->status;
}
}
// we create instances (actual objects) of a class using 'new'
$yourCar = new Car();
$myCar = new Car();
// use the '->' operator to access an object's members
$yourCar->color = 'red';
$yourCar->color = 'blue';
echo '<p>Your car color is ' . $yourCar->color . '.</p>';
//echo $yourCar->status;
echo '<p>Your car status is ' . $yourCar->getStatus() . '</p>';
$yourCar->setStatus('running');
echo '<p>Your car status is ' . $yourCar->getStatus() . '</p>';
echo '<p>My car status is ' . $myCar->getStatus() . '</p>';