1
I have a foreach
that makes the loop in the data of a file, this loop generates some values that are inserted in a array
with array_push
, I need to break these values inserted in this array
to generate multiples INSERT INTO
for some INSERT
had more than 2500 characters.
Code:
$dados = array();
foreach ($arquivo->entrada as $xyz):
...
array_push($dados, $valores);
endforeach;
implode(', ', $dados);
print_r(array_chunk($dados, 2, true));
With this, I can break the values every 2 entries of array
for example.
But how could I do that to have a query with several INSERT INTO
?
I don’t know how to do that by adding INSERT INTO 'tabela' VALUES
VALUE-DO-ARRAY ;
for each new split.
Example of data added to array
:
('2615509767','Challenge','','','Portuguese','','')
Example of data obtained with the print_r
:
Array
(
[0] => Array
(
[0] => ('2615509767','Challenge','','','Portuguese','','')
[1] => ('2178947891','Name','','','Portuguese','','')
)
[1] => Array
(
[2] => ('1877844784','City','','','English','','')
)
)
Example of code desired:
INSERT INTO 'tabela' VALUES ('2615509767','Challenge','','','Portuguese','',''), ('2178947891','Name','','','Portuguese','','');
INSERT INTO 'tabela' VALUES ('1877844784','City','','','English','','');
How could I do this in with php?
Note, put
2
in thearray_chunk
as an example to the question, my query ofINSERT
has many values, and consequently would change this value to suit it.– Florida
the function
print_r()
passing true returns a string like the one of the right question? It wouldn’t just concatenate with the rest of the sql script?– Costamilam
@Guilhermecostamilam updated the data from
print_r
sorry for the discrepancy in the code. I don’t know exactly how to do this, nor do I remember how to do if I ever knew, so here I am.– Florida