3

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])

2 Answers 2

4

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/>";
}
Sign up to request clarification or add additional context in comments.

1 Comment

No, I don't mean it I want to make an array, no to echo that. I want save that to a variable
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.