0

my code is pretty straight forward:

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

problem is if the count of that array is 0.. it acts like it was greater than 0.

anyone know why this is happening?

3 Answers 3

5

Look at your condition

count($votes > 0)

should be

count($votes) > 0
Sign up to request clarification or add additional context in comments.

Comments

1

Your parentheses are mismatched.

Try:

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

Comments

0

What your are doing

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

What you are looking for:

count($votes) > 0

You don't want to count the result of the expression $count > 0, but you want the count as argument in the expression $count > 0 (where $count = count($votes))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.