예제 #1
0
파일: cd.php 프로젝트: jmalo34/1
        $float_price = (double) $new_price;
        if ($float_price != 0) {
            $formatted_price = number_format($float_price, 2);
            $this->price = $formatted_price;
        }
    }
    function getPrice()
    {
        return $this->price;
    }
}
$first_cd = new CD("Master of Reality", "Black Sabbath", "images/reality.jpg");
$second_cd = new CD("Electric Ladyland", "Jimi Hendrix", "images/ladyland.jpg");
$third_cd = new CD("Nevermind", "Nirvana", "images/nevermind.jpg");
$fourth_cd = new CD("IDGI", "The Internet", "images/default.mp4", 49.99);
$fourth_cd->setPrice("\$1.3925");
// instead of declaring the properties and values of each object, within the delcaration, as below, we passsing to the method an argument for each property that we want to set.
// $first_cd = new CD();
// $first_cd->title = "Master of Reality";
// $first_cd->artist = "Black Sabbath";
// $first_cd->cover_art = "images/reality.jpg";
// $first_cd->price = 10.99;
//
// $second_cd = new CD();
// $second_cd->title = "Electric Ladyland";
// $second_cd->artist = "Jimi Hendrix";
// $second_cd->cover_art = "images/ladyland.jpg";
// $second_cd->price = 10.99;
//
// $third_cd = new CD();
// $third_cd->title = "Nevermind";
예제 #2
0
        $float_price = (double) $new_price;
        if ($float_price != 0) {
            $formatted_price = number_format($float_price, 2);
            $this->price = $formatted_price;
        }
    }
    function getPrice()
    {
        return $this->price;
    }
}
$first_cd = new CD("Master of Reality", "Black Sabbath", "images/reality.jpg");
$second_cd = new CD("Electric Ladyland", "Jimi Hendrix", "images/ladyland.jpg");
$third_cd = new CD("Nevermind", "Nirvana", "images/nevermind.jpg");
$fourth_cd = new CD("I don't get it", "Pork Lion", "images/porklion.jpg", 49.99);
$fourth_cd->setPrice("1.394");
$cds = array($first_cd, $second_cd, $third_cd, $fourth_cd);
?>
<!DOCTYPE html>
<html>
<head>
    <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>
    <title>My CD Store</title>
</head>
<body>
    <div class="container">
        <?php 
foreach ($cds as $album) {
    $cd_price = $album->getPrice();
    echo "<div class='row'>\n                    <div class='col-md-6'>\n                        <img src='{$album->cover_art}'>\n                    </div>\n                    <div class='col-md-6'>\n                        <p>{$album->title}</p>\n                        <p>By {$album->artist}</p>\n                        <p>\${$cd_price}</p>\n                    </div>\n                </div>\n                ";
}