Probably a stupid question, but how is best to handle a variable that gets created by an if statement in PHP?
So, the below code would work but if I changed the number 10 to 30 then the if statement would be false and $class would be undefined, which would throw an error.
What is the best way to handle this? Should I just define $class as null before my if statement?
if( 10 < 20 ) {
$class = 'less';
}
echo '<div class="number ' . $class . '">10</div>';
$class=""before if statement