How can the NumberFormatter function in PHP be used effectively for converting strings with numbers and text into integers?

When dealing with strings that contain numbers and text, the NumberFormatter function in PHP can be used effectively to convert these strings into integers. This function can parse the numeric values from the string and return them as integers, ignoring any non-numeric characters. By specifying the appropriate locale and formatting style, the NumberFormatter function can accurately extract the numeric values from the mixed strings.

$formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
$number = $formatter->parse('There are 10 apples');
echo $number; // Output: 10