0

I searched the most topics and couldn't find something that helps me out.

I have the following 2 arrays from form submit

Array
(
    [0] => FDS
    [1] => FSS
)
Array
(
    [0] => test@test.com
    [1] => 0123456789
)

and I need to combine the values from the first array with the values of the second array and make a custom third array that should look like this:

Array
        (
            [0] => Array
                (
                    [code] => FDS
                    [info] => test@test.com
                )

            [1] => Array
                (
                    [code] => SM2
                    [info] => 0123456789
                )

        )

The html form inputs looks like this:

<input type="checkbox" name="code[]" value="FDS">
<input id="flexDeliveryEmailInput" type="text" name="info[]">
<input id="flexDeliverySMS" type="checkbox" name="code[]" value="FSS">
<input type="text" name="info[]">
Alex Suciu
  • 70
  • 2
  • 9

1 Answers1

2

Try the following form inputs instead:

<input type="checkbox" name="data[0][code]" value="FDS">
<input id="flexDeliveryEmailInput" type="text" name="data[0][info]">
<input id="flexDeliverySMS" type="checkbox" name="data[1][code]" value="FSS">
<input type="text" name="data[1][info]">

This will provide the merged array as you want it.

mega6382
  • 9,211
  • 17
  • 48
  • 69