1
Mine inputs
are being generated from a repetition of Javascript naming them as follows: input.setAttribute("name",`tubo_${i}`)
and input.setAttribute("name",`largura_${i}`)
My problem is when I need to handle and separate these values in PHP, I get the items via $_POST
.
print_r($_POST)
:
Array
(
[tubo_0] => tubo1
[largura_0] => largura1
[tubo_1] => tubo2
[largura_1] => largura2
)
I need to create a array
containing the values of pipes and another array
with the value of widths.
Follow my failed attempt:
extract($_POST);
$qtdModelos = (count($_POST)) / 2;
for ($i=0; $i < $qtdModelos ; $i++) {
$arrayTubo[] = $tubo_.$i;
$arrayLargura[] = $largura_.$i;
}
print_r($arrayTubo);
print_r($arrayLargura);
Upshot
Array
(
[0] => 0
[1] => 1
)
Array
(
[0] => 0
[1] => 1
)
Only the values of $i
are being stored, that is, the variables are not being "concatenated" the way I would like them to be.
It wouldn’t be right for you to do it for example: for ($i=0; $i < $qtdModel ; $i++) { $arrayTubo[] = $tubo_[$i]; $arrayLargura[] = $largura_[$i]; } ???
– Leo
Variables generated from the Extract ($_POST), in this example, the existing variables are $tubo_0, $tubo_1, $largura_0 and $largura_1. Need to store them within specific arrays for each property.
– Gabriel Ribeiro
Why don’t you
input.setAttribute("name",`tubo[${i}]['tubo']`)
andinput.setAttribute("name",`tubo[${i}]['largura']`)
? You’ll already have one array with the data organized.– Woss
The reply of Rafael S. solved my problem, in this way
${tubo_.$i}
.– Gabriel Ribeiro