本文整理汇总了PHP中Car::setMiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Car::setMiles方法的具体用法?PHP Car::setMiles怎么用?PHP Car::setMiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Car
的用法示例。
在下文中一共展示了Car::setMiles方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Car
$porsche->setMiles(1245);
$porsche->setImage("images/porsche.jpg");
$ford = new Car();
$ford->setMake_Model("2014 Ford f450");
$ford->setPrice(56892);
$ford->setMiles(12465);
$ford->setImage("images/ford.jpg");
$lexus = new Car();
$lexus->setMake_Model("2013 Lexus RX 350");
$lexus->setPrice(44700);
$lexus->setMiles(20000);
$lexus->setImage("images/lexus.jpg");
$mercedes = new Car();
$mercedes->setMake_Model("Mercedes Benz CLS550");
$mercedes->setPrice(39900);
$mercedes->setMiles(37979);
$mercedes->setImage("images/mercedes.jpg");
$cars = array($porsche, $ford, $lexus, $mercedes);
$cars_matching_search = array();
foreach ($cars as $car) {
if ($car->worthBuying($_GET["price"]) && $car->maxMileage($_GET["mileage"])) {
array_push($cars_matching_search, $car);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Car Dealership</title>
示例2: foreach
$output = "";
foreach ($cars as $car) {
$output = $output . "<div class='row'>\n <div class='col-md-6'>\n <img src=" . $car->getPicture() . ">\n </div>\n <div class='col-md-6'>\n <p>" . $car->getModel() . "</p>\n <p>By " . $car->getPrice() . "</p>\n <p>\$" . $car->getMiles() . "</p>\n </div>\n </div>\n ";
}
return $output;
});
$app->get("/car_search", function () {
return "\n <!DOCTYPE html>\n <html>\n <head>\n <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css'>\n <title>Find a Car</title>\n\n </head>\n <body>\n <div class='container'>\n <h1>Find a Car!</h1>\n <form action='/view_results'>\n <div class='form-group'>\n <label for='price'>Enter Maximum Price:</label>\n <input id='price' name='price' class='form-control' type='number'>\n <label for='mileage'>Enter Maximum Miles:</label>\n <input id='mileage' name='mileage' class='form-control' type='number'>\n\n </div>\n <button type='submit' class='btn-success'>Submit</button>\n </form>\n </div>\n </body>\n </html>\n ";
});
$app->get("/view_results", function () {
$porsche = new Car("/pictures/porsche.jpg", "2014 Porsche 911", null, 7864);
//$porsche->make_model = "2014 Porsche 911";
//$porsche->price = 114991;
//$porsche->miles = 7864;
$porsche->setModel("Acura");
$porsche->setMiles(10000);
$ford = new Car("/pictures/ford.jpg", "2001 Ford F450", 55995, 14241);
/*$ford->make_model = "2011 Ford F450";
$ford->price = 55995;
$ford->miles = 14241;*/
$lexus = new Car("/pictures/lexus.jpg", "2013 Lexus RX 350", 44700, 20000);
/*$lexus->make_model = "2013 Lexus RX 350";
$lexus->price = 44700;
$lexus->miles = 20000;*/
$mercedes = new Car("/pictures/mercedes.jpg", "Mercedes Benz CLS550", 39900, 37979);
/*$mercedes->make_model = "Mercedes Benz CLS550";
$mercedes->price = 39900;
$mercedes->miles = 37979;*/
$cars = array($porsche, $ford, $lexus, $mercedes);
$cars_matching_search = array();
foreach ($cars as $car) {
示例3: setImage
}
function setImage($new_image)
{
$this->image = $new_image;
}
function getImage()
{
return $this->image;
}
}
$first_car = new Car("Honda CRV", 12000, 150000, "img/jetta.jpg");
$second_car = new Car("Tesla S", 53000, 20000, "img/tesla.jpg");
$third_car = new Car("Deron's Highschool Volvo", 5000, 170000, "img/volvo.jpg");
$fourth_car = new Car("Jeep Cherokee", null, 68000, "img/cherokee.jpg");
$first_car->setMake("VW Jetta");
$second_car->setMiles(35000);
$third_car->setPrice(5800);
$cars = array($first_car, $second_car, $third_car, $fourth_car);
$cars_matching_search = array();
foreach ($cars as $car) {
$car_price = $car->getPrice();
$car_miles = $car->getMiles();
if (empty($_GET["price"])) {
if ($car_miles < $_GET["mileage"]) {
array_push($cars_matching_search, $car);
}
} elseif (empty($_GET["mileage"])) {
if ($car_price < $_GET["price"]) {
array_push($cars_matching_search, $car);
}
} elseif ($car_price < $_GET["price"] && $car_miles < $_GET["mileage"]) {