phpvariablessingular

Singular or Plural setting to a variable. PHP


There are a lot of questions explaining how to echo a singular or plural variable, but none answer my question as to how one sets a variable to contain said singular or plural value.

I would have thought it would work as follows:

$bottom="You have favourited <strong>$count</strong> " . $count == 1 ? 'user':'users';

This however does not work.

Can someone advise how I achieve the above?


Solution

  • This will solve your issue, thanks to mario and Ternary operator and string concatenation quirk?

    $bottom = "You have favourited <strong>$count</strong> " . ($count == 1 ? 'user':'users');