2

Without looping through each value in an array, is there any shortcut to checking whether it contains values over 0?

Eg

array(3,0,0) would be TRUE

array(0,0,0) would be FALSE

array(-2,0,-3) would be FALSE

0

1 Answer 1

22
if (max(array(3,0,0)) > 0) echo 'greater than 0';
Sign up to request clarification or add additional context in comments.

2 Comments

I am uncertain if this qualifies as a true shortcut. It may be shorter to type in code, but the implementation cannot be more efficient than a loop.
@Feysal are we talking about premature micro optimization? If yes: don't do it...

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.