Welcome Guest, Not a member yet? Register   Sign In
Count returns 1 when empty
#1

[eluser]jakeone[/eluser]
Hi

I have a series of checkboxes. I want to see how many are checked, so I do the following:

Code:
$checkboxCount = count($this->input->post("myCheckboxes"));

This returns 1, even when I have not checked any of the boxes (but returns the correct number when I do check some of the boxes)

Maybe this is the wrong way to go about it, I'm not sure.

Any ideas?

Thanks

Jake
#2

[eluser]WanWizard[/eluser]
The method returns FALSE when the variable requested is not present in the array, which is what happens with checkboxes when you don't check any of them:
Code:
$checkboxes = $this->input->post("myCheckboxes");
$checkboxCount = $checkboxes === FALSE ? 0 : count($checkboxes);




Theme © iAndrew 2016 - Forum software by © MyBB