0
0
PHPprogramming~10 mins

Array sort functions 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 sort the array in ascending order.

PHP
<?php
$numbers = [4, 2, 8, 6];
[1]($numbers);
print_r($numbers);
?>
Drag options to blanks, or click blank then click option'
Arsort
Bsort
Casort
Dksort
Attempts:
3 left
💡 Hint
Common Mistakes
Using rsort which sorts in descending order.
Using ksort which sorts by keys, not values.
2fill in blank
medium

Complete the code to sort the array in descending order.

PHP
<?php
$letters = ['a', 'd', 'b', 'c'];
[1]($letters);
print_r($letters);
?>
Drag options to blanks, or click blank then click option'
Arsort
Bsort
Casort
Dksort
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort which sorts in ascending order.
Using ksort which sorts by keys.
3fill in blank
hard

Fix the error in the code to sort the array by keys in ascending order.

PHP
<?php
$ages = ['John' => 25, 'Jane' => 22, 'Doe' => 30];
[1]($ages);
print_r($ages);
?>
Drag options to blanks, or click blank then click option'
Aksort
Brsort
Csort
Dasort
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort or asort which sort by values.
Using rsort which sorts in descending order.
4fill in blank
hard

Fill both blanks to sort the array by values in ascending order while preserving keys.

PHP
<?php
$scores = ['Alice' => 85, 'Bob' => 92, 'Charlie' => 78];
[1]($scores);
print_r($scores);
?>
Drag options to blanks, or click blank then click option'
Aarsort
Bksort
Casort
Drsort
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort which reindexes keys.
Using ksort which sorts by keys.
5fill in blank
hard

Fill all three blanks to sort the array by values in descending order while preserving keys.

PHP
<?php
$grades = ['Math' => 90, 'Science' => 85, 'English' => 88];
[1]($grades);
print_r($grades);
?>
Drag options to blanks, or click blank then click option'
Aasort
Brsort
Cksort
Darsort
Attempts:
3 left
💡 Hint
Common Mistakes
Using rsort which does not preserve keys.
Using ksort which sorts by keys.