0
Hey, guys, all right?
I have a problem with a project I’m working on. I receive a form where the user informs the data but in this form, it is possible that he click a button to insert new inputs and inform other data.
The array I’m testing is this: (But it may vary as the user enters other fields).
array:8 [▼
"name" => array:3 [▼
0 => "101"
1 => "102"
2 => "103"
]
"gate" => array:3 [▼
0 => "1"
1 => "1"
2 => "1"
]
"chairs_initial" => array:3 [▼
0 => "80"
1 => "161"
2 => "242"
]
"chairs_final" => array:3 [▼
0 => "160"
1 => "241"
2 => "322"
]
"tickets_avaliable" => array:3 [▼
0 => "80"
1 => "80"
2 => "80"
]
"price_full" => array:3 [▼
0 => "40"
1 => "40"
2 => "40"
]
"price_half" => array:3 [▼
0 => "20"
1 => "20"
2 => "20"
]
"plant_sector" => array:3 [▼
0 => UploadedFile {#291 ▶}
1 => UploadedFile {#303 ▶}
2 => UploadedFile {#287 ▶}
]
]
And in it I go the following way:
<?php
foreach ($temp_sectors as $i => $temp) {
foreach ($temp as $j => $val) {
$sec[$j] = $val;
dd($sec);
}
}
And I always get the return of the first position of the name so:
0 => "101"
No access to 'Gate', 'chairs_initial', 'chairs_final'... I do not know if there is another way, but what I would like to mount is to separate this data according to the position in a temporary array, example:
array:0 [▼
"name" => "101"
"gate" => "1"
"chairs_initial" => "80"
...
]
array:1 [▼
"name" => "102"
"gate" => "1"
"chairs_initial" => "161"
...
]
array:2 [▼
"name" => "103"
"gate" => "1"
"chairs_initial" => "242"
...
]
So I can after that perform a foreach on this temporary array and insert the data into my database. I don’t know if there’s another simpler way, but if there is I’d like to understand it.
From now on, thank you!
The keys are not dynamic, it was just that! Haha. I didn’t remember the array_map. Thank you very much!
– Tiago Paza