4.1 PHP Arrays - Exercises
Due No due date Points 8 Questions 8
Question 1 1 pts
Use the correct function to output the number of items in an array. Fill in the blank.
$fruits = array("Apple", "Banana", "Orange");
echo ;
Question 2 1 pts
Output the second item in the $fruits array.
$fruits = array("Apple", "Banana", "Orange");
echo ;
Question 3 1 pts
Create an associative array containing the age of Peter, Ben and Joe.
$age = array("Peter" "35", "Ben" "37", "Joe" "43");
Question 4 1 pts
Here you see an associative array. Output "age" of Ben.
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
echo "Ben is " . . " years old.";
Question 5 1 pts
Loop through an associative array and output the key and the value.
foreach ($age as $x => $y) {
echo "Key=" . $x . ", Value=" . $y ;
}
Question 6
1 / 1 pts
Use the correct array method to sort the $colors array alphabetically.
$colors = array("red", "green", "blue", "yellow");
sort($colors);
Question 7
0 / 1 pts
Use the correct array method to sort the $colors array descending alphabetically.
$colors = array("red", "green", "blue", "yellow");
rsort($colors);
Question 8 1 pts
Use the correct array method to sort the $age array according to the values.
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
;