0

I have a code that counts the number of companies. I would like to add word company or companies if number is bigger >

0 companies
1 company
2 companies
.... and so on

The code I use is as follows:

echo $activeCompanies = Model_Company::search(array("count_only"=>true));
JJJ
  • 32,902
  • 20
  • 89
  • 102
Nunivo
  • 21
  • 1
  • 1
    possible duplicate of [function switching between singular and plural?](http://stackoverflow.com/questions/4728933/function-switching-between-singular-and-plural) – Marc Mar 31 '15 at 11:55

1 Answers1

4

I usually use something like this

echo "{$activeCompanies} compan".($activeCompanies == 1 ? "y" : "ies");

See the following link for more information on ternary operators: http://us2.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary

Matt Bolt
  • 332
  • 1
  • 2
  • 9