PHP Version
4.0.4+
var_dump(ctype_digit('1234'));  // bool(true)
var_dump(ctype_digit('0123'));  // bool(true)

var_dump(ctype_digit(' 123 ')); // bool(false)
var_dump(ctype_digit('3.14'));  // bool(false)
var_dump(ctype_digit('-123'));  // bool(false)
var_dump(ctype_digit(''));      // bool(false)

/* As of PHP 8.1.0, passing non-string arguments is no longer supported. */
var_dump(ctype_digit(123)); // bool(false)
var_dump(ctype_digit(1e3)); // bool(false)
ctype_digit(mixed $text): bool
/* int type, integer within the ASCII range (-128 to 255) */
$x = 65; // 65, an integer between -128 and 255, is considered the ASCII value for the character 'A'
var_dump(ctype_digit($x)); // false => treated as the string 'A'

/* int type, integer outside the ASCII range (-128 to 255) */
$y = 1234; // 1234, an integer outside the -128 to 255 range, is converted to the string '1234'
var_dump(ctype_digit($y)); // true => treated as the string '1234'
$x = 65;

var_dump(ctype_digit($x));           // false => unintended result
var_dump(ctype_digit((string)$x));   // true
$var = ' 123 ';

var_dump(ctype_digit($var));       // false
var_dump(ctype_digit(trim($var))); // true
$user_input = trim($_POST['age']);

if (ctype_digit($user_input)) {
    // Process the input if it consists only of digits.
    $age = intval($user_input); // Can be converted to an integer for further use.
    echo "Age is {$age}.";
} else {
    echo "Please enter your age using only numbers.";
}