How can regular expressions be used to determine if a variable is an integer in PHP?

Regular expressions can be used to determine if a variable is an integer in PHP by checking if the variable contains only digits. This can be achieved by using the preg_match function with a regular expression pattern that matches only digits.

$variable = '123';

if (preg_match('/^\d+$/', $variable)) {
    echo 'The variable is an integer.';
} else {
    echo 'The variable is not an integer.';
}