Question: i got below code from here and its working fine in PHP and i am getting the expected results. However when i open the web
i got below code from here and its working fine in PHP and i am getting the expected results. However when i open the web browser in ampps, the estatics is not looking good
name $name;
$thisdiscount $discount;
Product class to represent a product
class Product
public $name;
public $price;
public $quantity;
public function construct$name, $price, $quantity
$thisname $name;
$thisprice $price;
$thisquantity $quantity;
DiscountedProduct class inheriting from Product, with an additional category property
class DiscountedProduct extends Product
public $category;
public function construct$name, $price, $quantity, $category
parent::construct$name, $price, $quantity;
$thiscategory $category;
Function to calculate the final price after applying the category discount
function calculateDiscountedPrice$discountedProduct
$discountedPrice $discountedProductprice $discountedProductcategorydiscount;
return $discountedPrice;
Create category objects
$clothingCategory new CategoryClothing; discount
$electronicsCategory new CategoryElectronics; discount
$booksCategory new CategoryBooks; discount
Create product objects and categorize them
$products
"Clothing"
new DiscountedProductTShirt", $clothingCategory
new DiscountedProductJeans $clothingCategory
"Electronics"
new DiscountedProductSmartphone $electronicsCategory
new DiscountedProductLaptop $electronicsCategory
"Books"
new DiscountedProductPHP Guide", $booksCategory
new DiscountedProductJavaScript Guide", $booksCategory
;
Output product details
foreach $products as $categoryName $productArray
foreach $productArray as $product
$finalPrice calculateDiscountedPrice$product;
echo "Product: $productname
;
echo "Original Price: $ numberformat$productprice,
;
echo "Category: $productcategoryname
;
echo "Discount: $productcategorydiscount
;
echo "Final Price after Discount: $ numberformat$finalPrice,
;
i get below view with ampps brower. Can you help me improve it so it can be spaced well "Iterate through the $products array and for each
product"
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
