How can the results of preg_grep in PHP be manipulated or filtered further for specific requirements?

When using preg_grep in PHP, the results can be further manipulated or filtered by using array functions such as array_filter or array_map. These functions allow you to apply additional conditions or transformations to the results returned by preg_grep, enabling you to meet specific requirements.

// Example of using preg_grep and array_filter to further filter results
$patterns = ['/apple/', '/banana/', '/orange/'];
$fruits = ['apple', 'banana', 'orange', 'grape', 'pear'];

$filtered_fruits = preg_grep($patterns, $fruits);
$specific_fruits = array_filter($filtered_fruits, function($fruit) {
    return strlen($fruit) > 5; // Filter fruits with more than 5 characters
});

print_r($specific_fruits);