I am posting multiple checkboxes, and putting them into an array – for example: "tags[]"
When posting them, I am imploding them with commas.
If NO tags are checked on the form, and then posted, I get errors as the script is trying to implode something that isn't there.
I have tried using something like this:
if (isset($_POST['tags'])){
$tags = implode(", ", noescape($_POST['tags']));
}
What is the best way to check if it exists, then implode it?
isset, array_key_exists?
Best Answer
You could do it in one line, in this situation
isset
andarray_key_exist
would give you the same result but then you may want to check if$_POST['tags']
is an array...or
You can test here : http://codepad.org/XoU4AdsJ