I would like to post data in checkboxes, as like
<?php foreach($data as $foreignid => $id): ?>
<input type="checkbox"
name="photoids[<?php echo $foreignid; ?>]"
value="<?php echo $id;?>"
/>
If I go this way only one key-value pair remains in my $_POST array.
If I leave the photoids[] array empty, (not echoing out the $foreignid) all of the key-value pairs remains in $_POST array, but then i don’t have access to the $foreignid variable which that I need in my code.
What is the best workaround for this problem?
Use this:
And then parse keys in
$_POSTarray that begin withphotoidsto obtain foreignid.Or use this:
And then parse values to obtain foreignid and id.
Of course, assuming that underscore ‘_’ will not show up in foreignid or id.
You can parse name or value using:
$arr[0]will contain 123 and$arr[1]will contain 987.