For example, I have an array like this:
array(4) ( “a” => string(0) “” “b” => string(0) “” “c” => string(0) “” “d” => string(0) “” )
None of given values should be empty.
At the moment, I use this:
if (!empty($_POST['x']['a']) && !empty($_POST['x']['b']) && !empty($_POST['x']['c']) && !empty($_POST['x']['d']))
…and that sucks from readability aspect.
Note: Array is associative.
Some Explanation: Empty() is the Opposite of a Boolean Variable,
array_filterremoves all elements that equal false (which is!empty()) and this count must match the expectation of 4 elements then.If the number of elements is defined by the total of elements submitted (empty or not), use count() instead the magic number: