These functions are designed for precise number type validation:isInteger checks if a value is an integer (including string representations of integers).isFloat verifies if a value is a floating-point number (including string representations of decimals).They handle all number formats (positive, negative, leading zeros, dots at start/end) while rejecting non-numeric values (booleans, arrays, null).<?php function isInteger(mixed $val): bool { if (!is_scalar($val) || is_bool($val)) { return false; } if (is_int($val)) { return true; } if (isFloat($val)) { return false; } return preg_match('~^((?:\+|-)?[0-9]+)$~', (string) $val) === 1; } function isFloat(mixed $val): bool { if (!is_scalar($val) || is_bool($val)) { return false; } if (gettype($val) === "double") { return true; } if (!is_string($val)) { return false; } return preg_match('/^[+-]?(\d*\.\d+|\d+\.\d*)$/', $val) === 1; } $testValues = [ 42, '42', '+42', '-42', '0042', '000', PHP_INT_MAX, (string) PHP_INT_MAX, 3.14, '3.14', '.5', '5.', '0.5', '5.0', '+3.14', '-3.14', '0.0', '00.5', '5.00', '-.5', '-5.', null, [], true, false, 'string', '123abc', '12.3.4', '++12', '--12', '12 ', ' 12', '', '1e5', 1e5, ]; foreach ($testValues as $value) { $display = match (true) { is_null($value) => 'null', is_array($value) => '[]', is_bool($value) => $value ? 'true' : 'false', default => $value }; $type = gettype($value); echo "$display: $type"; echo " | isInteger: " . (isInteger($value) ? 'yes' : 'no'); echo " | isFloat: " . (isFloat($value) ? 'yes' : 'no'); echo PHP_EOL; }?>