How can PHP be used to filter values in an array based on specific criteria?

To filter values in an array based on specific criteria in PHP, you can use the array_filter() function. This function takes an array and a callback function as arguments. The callback function defines the criteria for filtering the array values. The array_filter() function will then return a new array containing only the values that meet the specified criteria.

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

// Filter values greater than 5
$filteredArray = array_filter($array, function($value) {
    return $value > 5;
});

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