查找字符串中的最后一个数值

I have this string #22aantal283xuitvoeren. What is the best way to find the last numeric value in a string? (283 in this case)

I don't think chop() or substr() is the wat to go.

You can use preg_match_all and match all digits.
Then the last item in the array is the last number in the string.

$s = "#22aantal283xuitvoeren";
preg_match_all("/\d+/", $s, $number);
echo end($number[0]); // 283

https://3v4l.org/44VUJ

You could try preg_match_all():

$string = "#22aantal283xuitvoeren";

$result = preg_match_all(
    "/(\d+)/",
    $string,
    $matches);

    $lastNumericValueInString = array_pop($matches[1]);

    echo $lastNumericValueInString;

Echoes 283

Here is a solution without regex.

Basically loop from back to front until the first number is found. Then, loop until the first non-number is found.

$string = "#22aantal283xuitvoeren";

for($i = strlen($string) - 1; $i >= 0; --$i) {
    if(is_numeric($string[$i])) {
        // found the first number from back to front
        $number = $string[$i];
        while(--$i >= 0 && is_numeric($string[$i])) {
            $number = $string[$i].$number;
        }
        break;
    }
}
// $number is now "283"
// if you want an integer, use intval($number)