I’m trying to find the number of input boxes that aren’t empty, but I’m getting a value of 1 every time. what am I doing wrong?
foreach( $_POST as $key=> $value ) {
if ($value!='' && $key!='add') {
$count = count($value);
}
}
echo $count;
You’re simply redefining the
$countvariable to becount($value)(which is always1since$valueis not an array), not incrementing it.Use the increment operator instead to add 1 to
$countwhen appropriate:You’re also probably better using
empty(..)for your checks, like so: