I have 2 output from a php function as below
First output gives me some thing like this
INSERT INTO "table1" ('column1', 'column2', 'column3') VALUES (?,?,?)
INSERT INTO "table2" ('column1', 'column2', 'column3','column4','column5') VALUES (?,?,?,?,?)
Other output gives
Array = (
1 => 'value1',
2 => 'value2',
3 => 'value3',
)
Array = (
1 => 'value1',
2 => 'value2',
3 => 'value3',
4 => 'value4',
5 => 'value5',
)
and now I want to do the following..
How can I replace the “?” in the first INSERT QUERY with values value1, value2 and value3 and same way for the second query the values in the second array.
regards
Generic solution:
example on Codepad
Note: If you want to replace
?only betwen parenthesis, use a lookbehind like this:preg_replace('~\?(?=[^\(\)]*\))~e', '$array[$n++]', $query);