I have this array:
Array
(
[users] => Array
(
[0] => Array
(
[column] => email
[value] => [email protected]
)
[1] => Array
(
[column] => nickname
[value] => dpucci
)
)
[social] => Array
(
[0] => Array
(
[column] => user_id
[value] => opweirpor
)
)
)
Starting from this array I'll have to build a string that will look like this:
insert(users, array(email=>[email protected],nickname=>dpucci)
And another like this:
insert(social, array(user_id=>opweirpor)
This is what I am doing:
foreach ($tables as $table => $queries) {
foreach ($queries as $query) {
$insert .= $query['column'] . '=>' . $query['value'] . ',';
}
echo 'insert(' . $table . ', array(' . $insert . ')';
}
The problem is that the result I am getting is the following:
insert(users, array(email=>[email protected],nickname=>dpucci)
and:
insert(social, array(email=>[email protected], nickname=>dpucci, user_id=>opweirpor)
This is because the variable $insert is incremented each new loop and it is adding ALL the results instead that only the ones I need for each $tables loop.
How can I achieve the expected result?