0
0
PHPprogramming~10 mins

Indexed array creation in PHP - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an indexed array with three elements.

PHP
<?php
$fruits = array([1]);
print_r($fruits);
?>
Drag options to blanks, or click blank then click option'
A"apple", "banana", "cherry"
B"apple" => 1, "banana" => 2, "cherry" => 3
C1, 2, 3
D"apple"; "banana"; "cherry"
Attempts:
3 left
💡 Hint
Common Mistakes
Using key => value pairs which creates an associative array.
Separating values with semicolons instead of commas.
2fill in blank
medium

Complete the code to add a new element "orange" to the existing indexed array.

PHP
<?php
$fruits = array("apple", "banana", "cherry");
$fruits[] = [1];
print_r($fruits);
?>
Drag options to blanks, or click blank then click option'
A"orange"
B"melon"
C"grape"
D"pear"
Attempts:
3 left
💡 Hint
Common Mistakes
Adding the wrong fruit name.
Forgetting the quotes around the string.
3fill in blank
hard

Fix the error in the code to correctly create an indexed array with numbers 1 to 3.

PHP
<?php
$numbers = array([1]);
print_r($numbers);
?>
Drag options to blanks, or click blank then click option'
A1; 2; 3
B1 2 3
C"1", "2", "3";
D1, 2, 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using semicolons instead of commas.
Not separating values properly.
4fill in blank
hard

Fill both blanks to create an indexed array of even numbers from 2 to 6.

PHP
<?php
$evens = array([1], [2]);
print_r($evens);
?>
Drag options to blanks, or click blank then click option'
A2
B4
C6
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using odd numbers instead of even.
Including numbers outside the range 2 to 6.
5fill in blank
hard

Fill all three blanks to create an indexed array with the strings "red", "green", and "blue".

PHP
<?php
$colors = array([1], [2], [3]);
print_r($colors);
?>
Drag options to blanks, or click blank then click option'
A"red"
B"green"
C"blue"
D"yellow"
Attempts:
3 left
💡 Hint
Common Mistakes
Using colors not listed in the instruction.
Forgetting quotes around strings.