I have the array $var, and I'd like to return FALSE if one or more element in the array are empty (I mean, the string are "").
I think that array_filter()
is the better way, but I don't know how to filter it in this manner.
How can I do it?
To check if an array is null, use equal to operator and check if array is equal to the value null. In the following example, we will initialize an integer array with null. And then use equal to comparison operator in an If Else statement to check if array is null. The array is empty.
To check if an array contains an empty string, call the includes() method passing it an empty string - includes('') . The includes method returns true if the provided value is contained in the array and false otherwise.
If you really want to check if one or more empty strings exists, it's simple. You can do,
in_array('', $var, true);
It returns true if empty string(''
) exists in at-least any one of the array values, false otherwise.
You can refer this similar question too,
how to check if an array has value that === null without looping?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With