In: Computer Science
Please code the arrays. This is in PHP/HTML
Perform some calculations:
1. $ages = [24, 12, 10, 17, 23, 29, 35, 32, 30, 22] Using a FOR loop, calculate the sum and average of these numbers, then print them. Please provide legible output.
2. If I change the array to $ages = [1 => 24, 12, 10, 17, 23, 29, 35, 32, 30, 22] How will the program change? Re-run the program and provide output
3. Assume that the above array is an associative array as follows:
$ages = ['Sam' => 24, 'Tina' => 12, 'Liz' => 10, 'Tom' => 17, 'Dave' => 23, 'Sandra' => 29, 'Kris' => 35, 'Mike' => 32, 'Daja' => 30, 'Rajan' => 22]
Write a program to print each name and its associated age on a single line; i.e., Sam => 24 . . . and so on
Answer 1:
PHP code:
Output:
Answer 2:
The indexing of the array will now start from index 1 instead of index 0. Therefore, for loop should now be iterated over 1 to 10.
Output when program is run without modifying the FOR loop:
Modified program:
Output:
Answer 3:
PHP code:
Output:
FOR ANY HELP JUST DROP A COMMENT