Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check if an array have one or more empty values

Tags:

arrays

php

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?

like image 900
kwichz Avatar asked Apr 30 '11 20:04

kwichz


People also ask

How do you check if an array contains an empty value?

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.

How do you check if an array contains an empty string?

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.


1 Answers

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?

like image 106
Pratik Avatar answered Oct 01 '22 18:10

Pratik