Part 4: According to the Trip Advisor, the 10 best Restaurants in Atlanta based
ID: 3910418 • Letter: P
Question
Part 4: According to the Trip Advisor, the 10 best Restaurants in Atlanta based up votes for 2016 are as follows: Chama Gaucha Average Cost $40.50 Aviva by Kameel Average Cost $15.00 Bone's Restaurant- Average Cost $65.00 Umi Sushi Buckhead- Average Cost $40.50 Fandangles-Average Cost $30.00 Capital Grille Average Cost $60.50 Canoe - Average Cost $35.50 One Flew South - Average Cost $21.00 Fox Bros. BBQ-Average Cost $15.00 South City Kitchen Midtown Average Cost $29.00 Define an array (or arrays) that holds this information about Name and Average Cost of the 10 best Restaurants in Atlanta. Print a table of the Restaurants Name and Restaurants Average Cost for all 10 Restaurants. The second part of this program is to write a functions to modify your output that to prints the result of the table ordered by price and a second function to print the results of the table by name.Explanation / Answer
If you have any doubts, please give me comment...
<?php
function print_table(){
echo "<table>";
for($i=0; $i<count($arr); $i++){
echo "<tr><td>".$arr[$i]['name']."</td><td>.$arr[$i]['avg_cost'].</td></tr>";
}
echo "</table>";
}
function print_sort_by_price($arr){
for($i=0; $i<count($arr); $i++){
for($j=$i+1; $j<count($arr); $j++){
if($arr[$i]['price']>$arr[$j]['price']){
$t = $arr[$i];
$arr[$i] = $arr[$j];
$arr[$j] = $t;
}
}
print_table($arr);
}
}
function print_sort_by_name($arr){
for($i=0; $i<count($arr); $i++){
for($j=$i+1; $j<count($arr); $j++){
if($arr[$i]['name']>$arr[$j]['name']){
$t = $arr[$i];
$arr[$i] = $arr[$j];
$arr[$j] = $t;
}
}
print_table($arr);
}
}
$arr = [
{'name':'Chama Gaucha', 'avg_cost':40.50},
{'name':'Aviva by Kameel', 'avg_cost':15.00},
{'name':'Bone's Restaurent', 'avg_cost':65.00},
{'name':'Umi Sushi Buckhead', 'avg_cost':40.50},
{'name':'Fandangles', 'avg_cost':30.00},
{'name':'Capital Grille', 'avg_cost':60.50},
{'name':'Canoe', 'avg_cost':35.50},
{'name':'One Flew South', 'avg_cost':21.00},
{'name':'Fox Bros. BBQ', 'avg_cost':15.00},
{'name':'South CIty Kitchen Midtows', 'avg_cost':29.00}
];
print_table($arr);
print_sort_by_price($arr);
print_sort_by_name($arr);
?>