Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 2. Please create a PHP program that will incorporate TWO for loops which ar

ID: 3910444 • Letter: P

Question

Part 2. Please create a PHP program that will incorporate TWO for loops which are

nested. This program should populate a “Checker board” using alternating color

values are red and black. This checkerboard width = “300px”. Each cell height and

width should = “35px”. Border set to = “1px” cell padding =”1px” and cell spacing=”1px"

Part 3.

Program name Arrays and Functions

Consider the following array.

$month = array ('January', 'February', 'March', 'April',

'May', 'June', 'July', 'August',

'September', 'October', 'November', 'December');

Please code in this order

1 Write a standard for loop not FOREACH that prints these months in order.

2. Use a Function to Sort the months in alphabetical orderand print months that are now sorted.

3. Repeat Steps 1 and 2 use theforeach Statement

Part4

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...

2)

<!DOCTYPE html>

<html>

<head>

<style type="text/css">

.cell{

height:35px;

width:35px;

border:1px solid #000;

background:red;

}

.cell.alt{

background:black;

}

</style>

</head>

<body>

<?php

$k = 0;

echo "<table cellpadding='1px' cellspacing='1px'>";

for($i=0; $i<8; $i++){

echo "<tr>";

for($j=0; $j<8; $j++, $k++){

echo "<td class='cell".($k%2==0?" alt":"")."'></td>";

}

echo "</tr>"

}

echo "</table>";

?>

</body>

</html>

Part 3)

<!DOCTYPE html>

<html>

<body>

<?php

functions Sort($months){

for($i=0; $i<count($months); $i++){

for($j=$i+1; $j<count($months); $j++){

if($months[$i]>$months[$j]){

$temp = $months[$i];

$months[$i] = $months[$j];

$months = $temp;

}

}

}

}

$month = array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

foreach($month as $i=>$v){

echo $v."<br />";

}

Sort($month);

echo "<h3>After Sorting</h3>"

foreach($month as $i=>$v){

echo $v."<br />";

}

?>

</body>

</html>

Part 4)

<?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);

?>