I wan't to make an array from checkbox.
I've use array($_POST[test],$_POST[test1],$_POST[test2])
It works, but if once of array is NULL the array also NULL
So what I wan't is if once of array is NULL, it's not in array
Like this
$_POST['test']=NULL;
$_POST['test1']="ARAAY1";
$_POST['test2']="ARRAY2";
and it will be array($_POST[test1],$_POST[test2])
try something like
<input type="checkbox" name="options[]" value="one"/> one<br/>
<input type="checkbox" name="options[]" value="tow"/> tow<br/>
<input type="checkbox" name="options[]" value="three"/> three<br/>
$checked = $_POST['options'];
for($i=0; $i < count($checked); $i++){
echo "Selected " . $checked[$i] . "<br/>";
}
You can use is_null() to check if a value is NULL or isset() to check that it is set and not NULL. Then you can append that variable to the array if and only if it isn't NULL.
Even better do what @NullPointer has in their answer where you set up the form so that the checkbox values come in as an array to begin with.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With