- Sorting:
sort(),rsort(),asort()/arsort()(by value, keep keys),ksort()/krsort()(by key),usort()(custom) array_map(),array_filter(),array_reduce()in_array(),array_search(),array_key_exists()array_merge(),array_slice(),array_unique(),array_keys(),array_values(),array_sum()
PHP Array Functions
Sort, filter, map and search arrays.
✍️ 2 exercises in this lessonKey Takeaways: PHP Array Functions
Mastering PHP Array Functions helps you write clean and reliable PHP code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
PHP Array Functions Code Example
PHP<?php
$marks = [72, 95, 58, 88];
$passed = array_filter($marks, fn($m) => $m >= 60);
$curved = array_map(fn($m) => $m + 5, $marks);
rsort($marks);
echo implode(", ", $passed) . "<br>";
echo implode(", ", $curved) . "<br>";
echo implode(", ", $marks) . "<br>";
echo "Total: " . array_sum($marks) . "<br>";
var_dump(in_array(95, $marks));
Output
72, 95, 88 77, 100, 63, 93 95, 88, 72, 58 Total: 313 bool(true)
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
PHP Array Functions Practice Exercises
Check what you learned in “PHP Array Functions”.
/ 2 solved
Fill in the blank
Keep only items that pass a test.
$passed = ($marks, fn($m) => $m >= 60);
✓ Correct!
Not quite. Try again.
Multiple choice
Which function sorts an associative array by value and keeps the keys?
✓ Correct!
Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services