Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
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?
Look at your condition
count($votes > 0)
should be
count($votes) > 0
Add a comment
Your parentheses are mismatched.
Try:
if( count( $votes ) > 0 ){ do something... } else { do something else }
What your are doing
count($votes > 0) == count (array() > 0) == count (true) == true
What you are looking for:
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))
$count > 0
$count = count($votes)
Required, but never shown
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.
Explore related questions
See similar questions with these tags.