Rickus Harmse Rickus Harmse -4 years ago 156
PHP Question

php inline if statement not working

I am not sure what I am doing wrong, but the inline if statement always returns true, even if it is not supposed to.

I have the following statement

<?php echo ($total == 'Scratched' || ($total > 0 && $total < 65)) ? 'ffefef' : 'f7f7f7'; ?>


Just above this statement, I echo
$total
and that echoes out
0


At the top of the page I define
<?php $total = 0; ?>
, so
$total
is defined as an integer.

The above if statement only returns false if
$total > 64
but not when total is 0

Thanks in advance

Answer Source

This is working

<?php 
$total = 0;
echo ($total === 'Scratched' || ($total > 0 && $total < 65)) ? 'ffefef' : 'f7f7f7';
?>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download