If there are no elements in a array, why does count() return more than 0?
if (count($_POST['tickboxes']) > 0) {
echo "found";
}
$POST array structure:
Array
(
[ID] => 53
[tickboxes] =>
[dropdowns] =>
)
I was expecting 0 or null.
You are trying to
countDocs something that is not an array, but rather a string.As documented,
countreturns1for strings, regardless of their lengths.You can use the
strlenDocs function instead, as it counts the number of ascii characters in that string:Additionally, you can use the
emptyDocs language construct for this, it will check if it’s an empty array or a blank string, or the integer 0 or the string ‘0’ – and that last one may cause you grief (depending on what you are doing with it, i.e. if your users can send you such input).If
emptywould be an option for you, you can just spare that as well:Don’t forget to check if that key in the
$_POSTarray exists if you do so. If you’re unsure,emptywon’t give you any warning: