php - Adding elements to an associative array during a loop -


i have loop:

foreach ($tables $table => $queries) {                     foreach ($queries $query) {                         $insert = array($query['column'] => $query['value']);                     } 

the $insert associative array should incremented of new elements each loop, logical result woud be:

 $insert = array($query['column'] => $query['value'], $query['column'] => $query['value'] ...etc); 

i tried using $insert[] , $insert .= , $insert += none of these give expected result

thanks help

once array's been defined, have use

$insert[$query['column']] = $query['value']; // sample #1 

to specify new key/value pair within $insert array.

if use

$insert[] = array(...); // sample #2 

you'll inserting new child array contains single key/value pair.

e.g. $insert before

$insert = array(    'foo' => 'bar' ); 

$insert after sample #1

$insert = array(     'foo' => 'bar',     'baz' => 'qux' ); 

$insert after sample #2:

$insert = array(    'foo' => 'bar'    0 => array(         'baz' => 'qux'    ) ); 

Comments