$age = 25; if (is_int($age)) { echo "Age is an integer."; } else { echo "Age is not an integer."; }
$number = "100"; if (is_int((int) $number)) { echo "Number is an integer."; } else { echo "Number is not an integer."; }
$data = 123; if (filter_var($data, FILTER_VALIDATE_INT) === false) { echo "Data is not an integer or string containing integer."; } else { echo "Data is an integer or string containing integer."; }There are many PHP packages and libraries available for validation, but some popular ones are: - Symfony Validator Component - Laravel Validation - Respect Validation