giving a CSS class as part of a PHP if else statement

Is there a good way of calling a css class as part of a PHP if else statement? What I am trying to do is change the background color of a div that is a part of the html depending on the value of the results from a php if else statement.

php

 if(!empty($check_availability)){
     echo <div id="1"> do something <div> 
    // make the div background green if this is true
    }
    else {
    <div id="2"> do something else instead<div>
    //make backgound red if this is true
    }

html

<div id="container"> <!-- <<<<<<< this is the div that I want to change the background color of depending on results from the php -->
<div id="1"></div>
<div id="2"></div>
</div>

Answer

Solution:

I assuming you are talking about conditionally adding classes to divs. good is subjective, but this is what I normally do.

$class = !empty($check_availability) ? 'green-class' : 'red-class';
echo "<div class='{$class}'> do something <div>";

Source