2012-05-15 51 views
-2

在Controller中最好顯示消息的方式是?必須顯示計數文章。在控制器中顯示消息的最佳方式

$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; 

也許其他的方式?

回答

0
if($c > 0)) 
{ 
    return "There are $c article(s) on this site."; 
} 
else 
{ 
    return "There are no articles on this site."; 
} 

這樣的事情?

+0

你有點忽視OP正在試圖*正確*複數詞「文章」。 – jprofitt

相關問題