-2

コントローラーでメッセージを表示するのに最適な方法はどれですか? カウントの記事を表示する必要があります。

$c = count($articles);

if($c == 0) {
  return "On site are 0 articles";
} elseif ($c == 1){
  return "On site is 1 article";
} else {
  return "On site are" . $c . "articles";
}

また:

if($c == 1) {
  $text1 = 'is';
  $text2 = 'article'
} else {
  $text1 = 'are';
  $text2 = 'articles'
}

return "On site" . $text1 . $c . $text2;

多分他の方法?

4

2 に答える 2

0

外部の複数形化クラスを使用する場合があります。

Google の短い調査では、次の結果が返されました: http://kuwamoto.org/2007/12/17/improved-pluralizing-in-php-actionscript-and-ror/

次のように使用します。

echo 'On site ' . $c==1 ? 'is ' : 'are ' . isInflect.pluralize_if($c, 'article') . '.';

動詞 (is/are) を複数形/単数形にするライブラリが他にもあることは確かです。

于 2012-05-15T12:10:21.147 に答える
0
if($c > 0))
{
    return "There are $c article(s) on this site.";
}
else
{
    return "There are no articles on this site.";
}

そんな感じ?

于 2012-05-15T12:07:50.220 に答える