I want my function to do the following:
if price is 0
, return free
message.
If price is positive, show the price.
If price value is unavailable - for example: if the database cell for the price is null, or have a value like unknown
, then return unavailable
message.
So I came with this code:
function get_rate($foo,$bar) {
if ($bar== "something") {
//$test= "testing";
} elseif ($foo== 0) {
$message = 'Free';
} elseif ($foo> 0) {
$message = '$'.$foo;
} else {
$message = 'Unavailable';
}
return $message;
}
HTML:
<?= get_rate( $price) ?>
But for the values:
$price="unknown";
or if $price
is null, I'm still getting "Free" message.