I have an array
$data = array( 'a'=>'0', 'b'=>'0', 'c'=>'0', 'd'=>'0' );
I want to check if all array values are zero.
if( all array values are '0' ) {
echo "Got it";
} else {
echo "No";
}
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I suppose you could use
array_filter()to get an array of all items that are non-zero ; and useempty()on that resulting array, to determine if it’s empty or not.For example, with your example array :
Using the following portion of code :
Would show you an empty array, containing no non-zero element :
And using something like this :
Would get you the following output :
On the other hand, with the following array :
The $tmp array would contain :
And, as such, would not be empty.
Note that not passing a callback as second parameter to
array_filter()will work because (quoting) :