Complete the code to create an indexed array with three elements.
<?php
$fruits = array([1]);
print_r($fruits);
?>The array() function takes a list of values separated by commas to create an indexed array.
Complete the code to add a new element "orange" to the existing indexed array.
<?php $fruits = array("apple", "banana", "cherry"); $fruits[] = [1]; print_r($fruits); ?>
Using $array[] = value; adds a new element to the end of an indexed array.
Fix the error in the code to correctly create an indexed array with numbers 1 to 3.
<?php
$numbers = array([1]);
print_r($numbers);
?>Values inside array() must be separated by commas without semicolons or spaces only.
Fill both blanks to create an indexed array of even numbers from 2 to 6.
<?php $evens = array([1], [2]); print_r($evens); ?>
The array should contain the numbers 2, 4, and 6. Since there are only two blanks, the last number 6 is missing intentionally to test understanding.
Fill all three blanks to create an indexed array with the strings "red", "green", and "blue".
<?php $colors = array([1], [2], [3]); print_r($colors); ?>
The array should contain the three color strings exactly as given.