如何将多个数组合并为一个?
The problem comes when I am echoing more than one order on a page and submitting it. This is my form:
<input name="checkOrder['.($row['ord_no']).'][ord_no]" value="'.($row['ord_no']).'" type="checkbox" class="checkOrder" id="checkOrder">
<input type="hidden" name="checkOrder['.($row['ord_no']).'][item_seq_no]" value="'.$line_number.'" />
<input type="hidden" name="checkOrder['.($row['ord_no']).'][item_no]" value="'.$item_number.'" />
<input type="hidden" name="checkOrder['.($row['ord_no']).'][item_desc_1]" value="'.$item_description.'" /></input>
Right now my ouput is this:
Array ( [ord_no] => 1000007 [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1 )
Array ( [ord_no] => 1000008 [item_seq_no] => 1 [item_no] => 002 [item_desc_1] => item2 )
Array ( [ord_no] => 1000000 [item_seq_no] => 1 [item_no] => 003 [item_desc_1] => item3 )
Array ( [ord_no] => 1000001 [item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1 )
I would prefer this:
[checkOrder] => Array
(
[ord_no] => 1000007
(
[item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1
)
[ord_no] => 1000008
(
[item_seq_no] => 1 [item_no] => 002 [item_desc_1] => item2
)
[ord_no] => 1000000
(
[item_seq_no] => 1 [item_no] => 003 [item_desc_1] => item3
)
[ord_no] => 1000001
(
[item_seq_no] => 1 [item_no] => 001 [item_desc_1] => item1
)
)
So how do I change my form to create one big array rather than multiple or am I not thinking about this correctly. Right now I am inserting all of these that are checked into a table inside a foreach loop. Then sending one email outside my foreach. It is only inserting the first array order # into the email. When I actually need everyone that was checked. I believe with this other array I have in mind it will fix my problem. If you want more info please let me know.
Change your form to:
<input name="checkOrder['.($row['ord_no']).'][checked]" value="" type="checkbox" class="checkOrder" id="checkOrder">
<input type="hidden" name="checkOrder['.($row['ord_no']).'][ord_no]" value="'.($row['ord_no']).'" />
<input type="hidden" name="checkOrder['.($row['ord_no']).'][item_seq_no]" value="'.$line_number.'" />
<input type="hidden" name="checkOrder['.($row['ord_no']).'][item_no]" value="'.$item_number.'" />
<input type="hidden" name="checkOrder['.($row['ord_no']).'][item_desc_1]" value="'.$item_description.'" /></input>
if you now var_dump($_POST); you got:
[checkOrder] => Array
(
[1000007] => Array
(
[ord_no] => 1000007, [item_seq_no] => 1, [item_no] => 001, [item_desc_1] => item1, [checked]='on'
)
[1000008] => Array
(
[ord_no] => 1000008, [item_seq_no] => 1, [item_no] => 002, [item_desc_1] => item2, [checked]='on'
)
[1000000] => Array
(
[ord_no] => 100000, [item_seq_no] => 1, [item_no] => 003,[item_desc_1] => item3, [checked]='on'
)
[1000001] => Array
(
[ord_no] => 1000001, [item_seq_no] => 1, [item_no] => 001, [item_desc_1] => item1, [checked]='on'
)
)
[checked]='on'
is only there if you checked that in the Form.
Hope that helps.
I need to save just the order numbers outside the foreach
Then use array_keys($_POST['checkOrder'])
and you got the ids.
But it thing you should use instead of
<input name="checkOrder['.($row['ord_no']).'][checked]" value="" type="checkbox" class="checkOrder" id="checkOrder">
this
<input name="checkedOrders[]" value="'.($row['ord_no'].'" type="checkbox" class="checkOrder" id="checkOrder">
And then in $_POST['checkedOrders']
are all the ids that where checked in the form.
The rest will be still the same.