I have an nested Array like this:
array(3) {
[1]=> array(5) {
["firstname"]=> string(2) "john"
["name"]=> string(2) "dorian"
["email"]=> string(2) "[email protected]"
["sex"]=> string(1) "m"
["size"]=> string(1) "L" }
[2]=> array(5) {
["firstname"]=> string(2) "Sam"
["name"]=> string(2) "Stuard"
["email"]=> string(2) "[email protected]"
["sex"]=> string(1) "m"
["size"]=> string(1) "S" }
[3]=> array(5) {
["firstname"]=> string(2) "vanessa"
["name"]=> string(2) "sherbatzky"
["email"]=> string(2) "[email protected]"
["sex"]=> string(1) "w"
["size"]=> string(3) "S" } }
The number of the outermost arrays ( [1], [2], [3] ) can change.
I tried with something like
$columns = implode(", ",array_keys($insData));
$escaped_values = array_map('mysql_real_escape_string', array_values($insData));
$values = implode(", ", $escaped_values);
$sql = "INSERT INTO `user`($columns) VALUES ($values)";
but I didn't get it. :/