I want to do a quick if-then
to echo the s
if it has more than 1 hour. The variables are already assigned if I were to do it on the next line. Any kind of help I can on this is greatly appreciated.
$img3['tdiff'] = $img3['tdiff']." Hour".if($img3['tdiff']>1)
{
echo "s";
};
I pretty much want to add the s
if it has more than one hour... Please help me if you can, and thank you in advance!
Use the Ternary Operator: ?:
$img3['tdiff'] = $img3['tdiff'] . " Hour" . ( $img3['tdiff'] > 1 ? "s" : "" );
Though in this case you'd want to use a pluralization library.
if($img3['tdiff'] > 1) {
$s = "s";
} else {
$s = "";
}
$img3['tdiff'] = $img3['tdiff']. " Hour". $s;
Edit: added an else clause to avoid an undefined variable