How can the array_filter function be utilized effectively in PHP for filtering arrays based on specific criteria?

The array_filter function in PHP can be utilized effectively to filter arrays based on specific criteria by providing a callback function that determines whether each element should be included in the resulting array. This callback function should return true for elements that meet the criteria and false for those that do not. By using array_filter, you can easily create a new array containing only the elements that match the specified criteria.

// Example array to filter
$numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

// Filter the array to include only even numbers
$evenNumbers = array_filter($numbers, function($num) {
    return $num % 2 == 0;
});

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