What are some best practices for efficiently searching for specific numbers in a string using PHP functions?

When searching for specific numbers in a string using PHP functions, one efficient way is to use regular expressions. Regular expressions allow you to define a pattern that matches the numbers you are looking for. You can use functions like preg_match() to search for and extract the numbers from the string.

$string = "There are 5 apples and 10 oranges in the basket.";
$pattern = '/\d+/';
preg_match_all($pattern, $string, $matches);

foreach ($matches[0] as $match) {
    echo $match . "\n";
}