How can regular expressions (regex) be used to filter and sort an array in PHP more efficiently?

Regular expressions (regex) can be used to filter and sort an array in PHP more efficiently by using functions like `preg_grep()` and `preg_match()` to search for specific patterns within the array elements. By using regex, you can easily filter out elements that match certain criteria or sort the array based on specific patterns. This can be particularly useful when dealing with large arrays or complex filtering requirements.

// Example of using regex to filter and sort an array
$array = ["apple", "banana", "cherry", "date", "fig"];

// Filter array to only include elements starting with 'a' or 'b'
$filteredArray = preg_grep('/^[ab]/i', $array);

// Sort the filtered array alphabetically
sort($filteredArray);

print_r($filteredArray);