php - How to create an Array from the checked boxes
Get the solution ↓↓↓I have 1000 checkboxes of object fields and I want to create an Array from all the fields that I check after submitting using PHP can you tell me how to do it?
Answer
Solution:
well if you name your checkbox like this, you already have an array:
<input name="mycheckbox[]" value="1"> hello1
<input name="mycheckbox[]" value="2"> hello2
<input name="mycheckbox[]" value="3"> hello3
in PHP you will get:
print_t($_REQUEST['mycheckbox']);
/*
[
0 => '1',
0 => '2',
0 => '3'
]
*/
Answer
Solution:
<input type="checkbox" name="somename[]" value="somevalue">
if you need an array with numerical indices
or<input type="checkbox" name="someobject[property]" value="somevalue">
if you are looking for an associative array
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: a non well formed numeric value encountered
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.