Add item with different array

1

I have the following array ()

Array
(
    [nome_responsavel] => 
    [telefone] => 
    [email] => 
    [dependentenome] => Array
        (
            [0] => qqq
            [1] => qqq
            [2] => qqqq
        )

    [dependentedata] => Array
        (
            [0] => 2017-01-18
            [1] => 2017-01-04
            [2] => 2017-01-06
        )

)

I need to do an insert as follows

INSERT INTO tabela (nome, data) VALUES ('nome', 'data');

How can I do this, since I have an array with two different columns?

    
asked by anonymous 10.01.2017 / 21:21

1 answer

2

Would that be what you need?

$sql = 'INSERT INTO tabela (nome, data) VALUES ';
for($i = 0; $i < count($array['dependentenome']); $i++){
     $sqlValues[] = "('{$array['dependentenome'][$i]}', '{$array['dependentedata'][$i]}')";
}
$sql .= implode(', ', $sqlValues) . ';';

echo $sql;

Result:

  

INSERT INTO table (name, date) VALUES ('qqq', '2017-01-18'), ('qqqq', '2017-01-04'), ('qqqqq', '2017-01- 06 ');

    
10.01.2017 / 21:31