How can you use an IF statement to check if a variable is empty or has a value in PHP?

To check if a variable is empty or has a value in PHP, you can use an IF statement with the empty() function. The empty() function returns true if the variable is empty (or not set) or contains a falsey value (such as 0 or ""). Conversely, it returns false if the variable has a non-empty value.

$variable = ''; // or any value you want to check

if (empty($variable)) {
    echo 'Variable is empty';
} else {
    echo 'Variable has a value';
}