2

I am trying to fetch values from few - dynamically created HTML FORM & in action file, i am grabbing those values via $_POST. Please consider humbly, that i am using array in dynamic inputs like :

<input name="array1[]" />
<input name="array2[]" />
<input name="array3[]" />

So, that, after FORM SUBMIT, in action file, its giving :

         $a =    Array
        (
            [0] => 04/21/2017
            [1] => 04/19/2017
            [2] => 04/25/2017
            [3] => 04/25/2017
            [4] => 10/25/2017
        )

    $b=    Array
        (
            [0] => 11
            [1] => 34
            [2] => 12
            [3] => 12
            [4] => 2
        )

      $c=  Array
        (
            [0] => fghgthg
            [1] => ggfg
            [2] => fgfgfdgf
            [3] => fgfdgdgfgdh
            [4] => rgrgfgf
        )

Now, m having troubles in arranging this way :

$FinalArray = array(

array($a[0], $b[0], $c[0]),
array($a[1], $b[1], $c[1]),
array($a[2], $b[2], $c[2]),
array($a[3], $b[3], $c[3]),
......last line without comma

  );

And submitting in mysql table, so that i can easily retrieve it like :

step-1 : $FinalArray[0];
step-2 : $FinalArray[1]; 
.......goes on

Thanks, for help, in Advance.

1 Answer 1

1

This simple foreach help you in achieving your desired output.

Try this code snippet here

<?php

ini_set('display_errors', 1);

$a = Array
    (
    0 => "04/21/2017",
    1 => "04/19/2017",
    2 => "04/25/2017",
    3 => '04/25/2017',
    4 => "10/25/2017"
);

$b = Array
    (
    0 => 11,
    1 => 34,
    2 => 12,
    3 => 12,
    4 => 2
);

$c = Array
    (
    0 => "fghgthg",
    1 => "ggfg",
    2 => "fgfgfdgf",
    3 => "fgfdgdgfgdh",
    4 => "rgrgfgf",
);
$result=array();
foreach($a as $key => $value)
{
    $result[]=array($value,$b[$key],$c[$key]);
}
print_r($result);

Output:

Array
(
    [0] => Array
        (
            [0] => 04/21/2017
            [1] => 11
            [2] => fghgthg
        )

    [1] => Array
        (
            [0] => 04/19/2017
            [1] => 34
            [2] => ggfg
        )

    [2] => Array
        (
            [0] => 04/25/2017
            [1] => 12
            [2] => fgfgfdgf
        )

    [3] => Array
        (
            [0] => 04/25/2017
            [1] => 12
            [2] => fgfdgdgfgdh
        )

    [4] => Array
        (
            [0] => 10/25/2017
            [1] => 2
            [2] => rgrgfgf
        )

)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.