How can PHP variables be passed from an if statement to be used in a div element?

To pass PHP variables from an if statement to be used in a div element, you can set the variables within the if statement and then echo them within the div element outside of the if statement. This way, the variables will be accessible and can be displayed within the div element.

<?php
$var = ""; // Initialize variable
if (condition) {
    $var = "Value"; // Set variable within if statement
}
?>
<div>
    <?php echo $var; ?> <!-- Echo variable within div element -->
</div>