3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testValues = [ 'positives' => ['121', '231.45', '77,65', '9.456,77', '4,255.66'], // should pass 'negatives' => ['-121', '-231.45', '-77,65', '-9.456,77', '-4,255.66'], // should pass 'gibberish' => ['231.45a', '7a7,65', 'a9.456,77', '4,255.66a', 'aaaaaa'], // should fail ]; function customIsNumeric(string $value): bool { return is_numeric(str_replace(['.', ','], '', $value)); } foreach ($testValues as $category => $values) { var_dump($category); foreach ($values as $value) { var_dump(customIsNumeric($value)); } }
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
string(9) "positives" bool(true) bool(true) bool(true) bool(true) bool(true) string(9) "negatives" bool(true) bool(true) bool(true) bool(true) bool(true) string(9) "gibberish" bool(false) bool(false) bool(false) bool(false) bool(false)

preferences:
142.51 ms | 407 KiB | 5 Q