What are some best practices for filtering out unwanted elements from arrays in PHP, as demonstrated in the code snippet provided?

When working with arrays in PHP, it is common to encounter the need to filter out unwanted elements based on certain criteria. One way to achieve this is by using the array_filter() function, which allows you to specify a callback function that determines whether each element should be kept or removed. By defining a custom callback function that evaluates the elements based on the desired criteria, you can effectively filter out unwanted elements from the array.

// Example code snippet demonstrating how to filter out unwanted elements from an array in PHP

// Define an array with some elements
$numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Define a callback function to filter out even numbers
function filterEvenNumbers($number) {
    return $number % 2 != 0;
}

// Use array_filter() with the custom callback function to filter out even numbers
$filteredNumbers = array_filter($numbers, 'filterEvenNumbers');

// Output the filtered array
print_r($filteredNumbers);