Not sure if this is what you were up to, but ...
<?php # Given this array $arrays = array( 'foo' => array( 0 => 250, 1 => 247, 2 => 279, 3 => 249 ), 'bar' => array( 0 => 'AM PROV', 1 => 'AM PROV', 2 => 'AM PENS', 3 => 'AM PROV' ), 'schoo' => array( 0 => 'xxxx', 1 => 'yyy', 2 => 'zzz', 3 => 'aaa' ) ); # This code generates... $fields = array(); $inserts = array(); foreach ($arrays as $k => $v) { $fields[] = $k; } for ($i = 0; $i < count($arrays[$fields[0]]); $i++) { $vals = array(); foreach ($fields as $field) { $vals[] = $arrays[$field][$i]; } $inserts[] = 'INSERT INTO (' . implode(',', $fields) . ') VALUES ("' . implode('","', $vals) . '")'; } # This array /* $inserts = array( 'INSERT INTO (foo, bar, schoo) VALUES ("250", "AM PROV", "xxxx")', 'INSERT INTO (foo, bar, schoo) VALUES ("247", "AM PROV", "yyy")', 'INSERT INTO (foo, bar, schoo) VALUES ("279", "AM PENS", "zzz")', 'INSERT INTO (foo, bar, schoo) VALUES ("249", "AM PROV", "aaa")' ); */ var_dump($inserts);
Edit: Although I think you are missing the table name from your INSERT statements.
Edit2: you can shorten the code with array_keys like Frosty Z, and skip the first foreach file.
powerbuoy
source share