3v4l.org

run code in 300+ PHP versions simultaneously
<?php function intvaljunk($string) { $boolSignedNegative = false; $intIntStart = null; $intIntEnd = null; foreach (str_split($string) as $index => $char) { if (is_numeric($char)) { $boolSignedNegative = ( $boolSignedNegative === false && $index > 0 && is_null($intIntStart) && $string[$index - 1] === '-' ? true : $boolSignedNegative ); $intIntStart = is_null($intIntStart) ? $index : $intIntStart; $intIntEnd = is_null($intIntStart) ? $intIntEnd : $index; } else if (!is_null($intIntStart) && !is_null($intIntStart)) { break; } } return ( !is_null($intIntStart) && !is_null($intIntStart) ? intval(($boolSignedNegative ? '-' : '') . substr($string, $intIntStart, ($intIntEnd - $intIntStart) + 1)) : null ); } $signed_number_strings = ["--1", "---33", "+-444"]; foreach ($signed_number_strings as $string) { var_dump(intvaljunk($string)); }

preferences:
49.1 ms | 1631 KiB | 5 Q