In: Computer Science
This assignment is about creating a online movie rental
store. Use arrays and loops for this
assignment.
1) Create a web page containing a list of movie names available for
rent (at least 10 movies), so that each time you visit the home
page, you see a different order of movies in the list. The movie
names are required, all other information is optional.)
2) The rental price for each movie ranges between $1.99 to
$7.99.
• Create an associative array with a code for the movie as the key (e.g., movie1, movie2, etc.) and the associated rental price as the value. Display the array using the print_r() function.
• Sort the array according to the rental price in ascending order. Display the array again using the print_r() function.
• Calculate and display the average rental price for a movie.
• Find and display the two highest and two lowest rental prices.
Display these results on the same page.
Again, display appropriate warning/error messages as needed.
PHP program for given assignement is as bellow, if you have any query regarding program please do comment I will solve all your queries thank you.
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags-->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,
initial-scale=1, maximum-scale=1, minimum-scale=1,
user-scalable=no, minimal-ui, viewport-fit=cover">
<meta name="apple-mobile-web-app-capable"
content="yes">
<meta http-equiv="pragma"
content="no-cache"><meta http-equiv="cache-control"
content="no-store,no-cache">
<!-- Your app title -->
<title>Movies</title>
</head>
<body>
<div class="movies">
<h1>Movies</h1>
<ul>
<?php
//declared associative array movies
$movies= array(
"Avatar"=>"2","Inception"=>"2.5","Avengers"=>"4","Spiderman"=>"3.66","Deadpool"=>"5.44","Terminator"=>"6","Star
War"=>"4","The
Prestige"=>"3","Shadow"=>"4.65","Apollo"=>"2.3");
$movieNames=array_keys($movies);
//shuffling array to display list of movies in random sequence each time
shuffle($movieNames);
foreach($movieNames as $m)
{
echo "<li>".$m."</li>";
}
?>
</ul>
<?php
echo "<b>Array without sorting</b> <p>";
print_r($movies);
echo "<p/>";
//sorting array in ascending order
arsort($movies);
echo "<b> Array After Sorting </b><p>";
print_r($movies);
echo "<p/>";
$average = array_sum($movies)/count($movies);
echo "<b> Average Rental Of Movies
Is</b><p>:$".$average."<p/>";
$l = array_slice($movies,0,2,true);
$m= array_slice($movies,count($movies)-2,count($movies));
echo "<br/><b>Highest Rental
Prices:</b><p>";
$i=1;
foreach ($m as $key => $value) {
# code...
echo $i.")$".$value."<br/>";
$i++;
}
echo "<p/><b>Lowest Rental
Prices:</b><p>";
$i=1;
foreach ($l as $key => $value) {
# code...
echo $i.")$".$value."<br/>";;
$i++;
}
echo "</p>";
?>
</div>
</body>
</html>