How can you check if a variable is a whole number or a decimal number in PHP?

To check if a variable is a whole number or a decimal number in PHP, you can use the is_int() function to check if the variable is an integer (whole number) and the is_float() function to check if the variable is a float (decimal number). You can also use the is_numeric() function to check if the variable is a number in general.

$number = 5.5;

if (is_int($number)) {
    echo "The variable is a whole number.";
} elseif (is_float($number)) {
    echo "The variable is a decimal number.";
} else {
    echo "The variable is not a number.";
}