What is the recommended function in PHP to check if a variable contains only numbers?

To check if a variable contains only numbers in PHP, you can use the `ctype_digit()` function. This function returns true if all characters in the string are numerical digits. By using this function, you can easily validate if a variable contains only numbers before further processing it in your code.

$variable = "12345";

if (ctype_digit($variable)) {
    echo "The variable contains only numbers.";
} else {
    echo "The variable does not contain only numbers.";
}