Assuming your data comes from $_GET or $_POST , all data fields will be strings. This means that you must check in a call to one function :
if (in_array('', $list, TRUE)) { $error[] = "All fields are required."; }
This searches for strings that are exactly equal to the empty string. If you want to make comparisons free (more or less identical to the check empty() does), just delete the final TRUE .
EDIT Thinking about this, you don't need a rigorous comparison. I did this so that the valid value of the '0' field (which empty() did not allow), but it would also be allowed with free comparisons, since '0' != '' .
OTHER EDITING If you want to check that the length of the sting is more than two, you have to loop:
foreach ($list as $item) { if (strlen($item) < 2) { $error[] = "All fields are required."; break; } }
It will also "clear 0 ", assuming that by that you mean "do not allow the value 0 ". If you also want to disable '00' (or any other line that results in 0 ), you can change the if clause to this:
if (strlen($item) < 2 || (!(int) $item)) {
source share