0
0
PHPprogramming~10 mins

Array unique and flip 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 remove duplicate values from the array.

PHP
<?php
$numbers = [1, 2, 2, 3, 4, 4, 5];
$unique = [1]($numbers);
print_r($unique);
?>
Drag options to blanks, or click blank then click option'
Aarray_unique
Barray_flip
Carray_merge
Darray_map
Attempts:
3 left
💡 Hint
Common Mistakes
Using array_flip instead of array_unique.
Trying to use array_merge which combines arrays.
Using array_map which applies a callback to elements.
2fill in blank
medium

Complete the code to flip keys and values of the array.

PHP
<?php
$colors = ['red', 'green', 'blue'];
$flipped = [1]($colors);
print_r($flipped);
?>
Drag options to blanks, or click blank then click option'
Aarray_reverse
Barray_unique
Carray_flip
Darray_keys
Attempts:
3 left
💡 Hint
Common Mistakes
Using array_unique which removes duplicates.
Using array_reverse which reverses order but not keys and values.
Using array_keys which returns keys only.
3fill in blank
hard

Fix the error in the code to correctly remove duplicates and flip the array.

PHP
<?php
$items = ['a', 'b', 'a', 'c'];
$unique = [1]($items);
$flipped = array_flip($unique);
print_r($flipped);
?>
Drag options to blanks, or click blank then click option'
Aarray_flip
Barray_unique
Carray_merge
Darray_map
Attempts:
3 left
💡 Hint
Common Mistakes
Using array_flip first which does not remove duplicates.
Using array_merge which combines arrays incorrectly.
Using array_map which is not for removing duplicates.
4fill in blank
hard

Fill both blanks to create an array of unique values and then flip keys and values.

PHP
<?php
$fruits = ['apple', 'banana', 'apple', 'orange'];
$unique = [1]($fruits);
$flipped = [2]($unique);
print_r($flipped);
?>
Drag options to blanks, or click blank then click option'
Aarray_unique
Barray_flip
Carray_merge
Darray_reverse
Attempts:
3 left
💡 Hint
Common Mistakes
Using array_merge instead of array_unique.
Using array_reverse instead of array_flip.
Flipping before removing duplicates.
5fill in blank
hard

Fill all three blanks to remove duplicates, flip the array, and then get the keys of the flipped array.

PHP
<?php
$letters = ['x', 'y', 'x', 'z'];
$unique = [1]($letters);
$flipped = [2]($unique);
$keys = [3]($flipped);
print_r($keys);
?>
Drag options to blanks, or click blank then click option'
Aarray_unique
Barray_flip
Carray_keys
Darray_values
Attempts:
3 left
💡 Hint
Common Mistakes
Using array_values instead of array_keys.
Flipping before removing duplicates.
Skipping the step to get keys.