vendredi 27 janvier 2017

Adding an array of values to an existing array

I've got a foreach where I create an array out of id's, based on the submitted selected checkboxes from my form (which are `checkbox[$id]. So I end up with:

Checkboxes

Where 1, 2 and 3 are the submitted id's from the form. So far so good.

Now I also have an input field amount[$id]in my form. When selecting a checkbox, I can enter an amount for that row and submit the results. I need to add the values of amount to my array if id's. My end result should look like this:

[1 => ['amount' => '10'], 2 => ['amount' => '12'], 3 => ['amount' => '5'] // And so on

I tried merging, and array_push, but I seem to be doing it wrong, since I cannot figure it out. Any pointers?




Aucun commentaire:

Enregistrer un commentaire