For a project I am supposed to identify what is wrong with these scripts and fix them:
The first script:
<?php // Script 7.1 - soups1.php
/* This script creates and prints out an array. */
// Address error management, if you want.
// Create the array:
$soups = array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian'
);
// Try to print the array:
print "<p>$soups</p>";
// Print the contents of the array:
print_r ($soups);
?>
The second Script:
<?php // Script 7.2 - soups2.php
/* This script creates and prints out an array. */
// Address error management, if you want.
// Create the array:
$soups = array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian'
);
// Count and print the current number of elements:
$count1 = count ($soups);
print "<p>The soups array originally had $count1 elements.</p>";
// Add three items to the array:
$soups['Thursday'] = 'Chicken Noodle';
$soups['Friday'] = 'Tomato';
$soups['Saturday'] = 'Cream of Broccoli';
// Count and print the number of elements again:
$count2 = count ($soups);
print "<p>After adding 3 more soups, the array now has $count2 elements.</p>";
// Print the contents of the array:
print_r ($soups);
?>
Third Script:
<?php // Script 7.3 - soups3.php
/* This script creates and prints out an array. */
// Address error management, if you want.
// Create the array:
$soups = array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian',
'Thursday' => 'Chicken Noodle',
'Friday' => 'Tomato',
'Saturday' => 'Cream of Broccoli'
);
// Print each key and value:
foreach ($soups as $day => $soup) {
print "<p>$day: $soup</p>\n";
}
?>
The first script:
<?php // Script 7.1 - soups1.php
/* This script creates and prints out an array. */
// Address error management, if you want.
// Create the array:
$soups = array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian'
);
// Try to print the array:
print "<p>$soups</p>";
// Print the contents of the array:
print_r ($soups);
?>
The second Script:
<?php // Script 7.2 - soups2.php
/* This script creates and prints out an array. */
// Address error management, if you want.
// Create the array:
$soups = array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian'
);
// Count and print the current number of elements:
$count1 = count ($soups);
print "<p>The soups array originally had $count1 elements.</p>";
// Add three items to the array:
$soups['Thursday'] = 'Chicken Noodle';
$soups['Friday'] = 'Tomato';
$soups['Saturday'] = 'Cream of Broccoli';
// Count and print the number of elements again:
$count2 = count ($soups);
print "<p>After adding 3 more soups, the array now has $count2 elements.</p>";
// Print the contents of the array:
print_r ($soups);
?>
Third Script:
<?php // Script 7.3 - soups3.php
/* This script creates and prints out an array. */
// Address error management, if you want.
// Create the array:
$soups = array (
'Monday' => 'Clam Chowder',
'Tuesday' => 'White Chicken Chili',
'Wednesday' => 'Vegetarian',
'Thursday' => 'Chicken Noodle',
'Friday' => 'Tomato',
'Saturday' => 'Cream of Broccoli'
);
// Print each key and value:
foreach ($soups as $day => $soup) {
print "<p>$day: $soup</p>\n";
}
?>