0

I have a form that allows the user to select multiple "keys" and then dynamically add any amount of values after. I need to combine them tied to each "key" to insert as rows in CSV. example data from form submit:

$locations = array(loc1,loc2,loc3,loc4)
$input1 = array(A1,A2,A3,A4,A5)
$input2 = array(B1,B2,B3,B4,B5)
$input3 = array(C1,C2,C3,C4,C5)

Output as:

$OutToCVS = array(loc1,A1,A2,A3,A4,A5)
$OutToCVS = array(loc1,B1,B2,B3,B4,B5)
$OutToCVS = array(loc1,C1,C2,C3,C4,C5)
$OutToCVS = array(loc2,A1,A2,A3,A4,A5)
$OutToCVS = array(loc2,B1,B2,B3,B4,B5)
$OutToCVS = array(loc2,C1,C2,C3,C4,C5)
$OutToCVS = array(loc3,A1,A2,A3,A4,A5)
$OutToCVS = array(loc3,B1,B2,B3,B4,B5)
$OutToCVS = array(loc3,C1,C2,C3,C4,C5)
$OutToCVS = array(loc4,A1,A2,A3,A4,A5)
$OutToCVS = array(loc4,B1,B2,B3,B4,B5)
$OutToCVS = array(loc4,C1,C2,C3,C4,C5)

Any help would be appreciated.

1
  • Iterate over arrays and create result data. Commented Oct 13, 2020 at 20:22

1 Answer 1

1

Example code to start with:

foreach ($locations as $loc) {
    $OutToCVS[] = array_merge([$loc], $input1);
    $OutToCVS[] = array_merge([$loc], $input2);
    $OutToCVS[] = array_merge([$loc], $input3);
}

Fiddle.

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

3 Comments

Ok, this get me to where I can get an output like: Array ([0] => Array ( [0]=> loc1 [1] =>$input1 [2] =>input2) [1]=> loc2 [1] =>$input1 [2] =>input2)
I need it to give a round for each input with location repeated. Does this make sense?
Checking against it now. Just tried again, and not getting the correct results. I will update accordingly. Thank you.

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.