How can empty SESSION variables be properly initialized in PHP?

When dealing with empty SESSION variables in PHP, it's important to properly initialize them to avoid errors or unexpected behavior. To do this, you can check if the SESSION variable is set and not empty, and if it's not, assign it a default value. This ensures that the variable is always initialized and ready to be used in your code.

session_start();

// Check if SESSION variable is not set or empty, then initialize it with a default value
if (!isset($_SESSION['variable']) || empty($_SESSION['variable'])) {
    $_SESSION['variable'] = 'default_value';
}