What are common pitfalls to avoid when working with arrays in PHP, especially when sorting and filtering data?

One common pitfall when working with arrays in PHP is not specifying the correct comparison function when sorting data. This can lead to unexpected results or errors in the sorting process. To avoid this, always define a custom comparison function that suits the specific sorting requirements.

// Example of sorting an array of numbers in ascending order
$numbers = [5, 2, 8, 1, 9];
usort($numbers, function($a, $b) {
    return $a - $b;
});
print_r($numbers);