2011-09-12 33 views
0

我的代碼是非常簡單的:

if(count($votes > 0)) { do something } else { do something else } 

問題是,如果該數組的計數爲0 ..它的作用就像是大於0

任何人都知道爲什麼會發生這種情況?

回答

5

看看你的條件

count($votes > 0) 

應該

count($votes) > 0 
1

你的括號不匹配。

嘗試:

if(count($votes) > 0){ do something... } else { do something else } 
0

什麼你正在做

count($votes > 0) == count (array() > 0) == count (true) == true 

什麼你正在尋找:

count($votes) > 0 

你不想算表達$count > 0結果,但是您希望計數作爲表達式中的參數10(其中$count = count($votes)