I've been scouring SO this afternoon for a viable solution to my use case. I haven't found it.
Use Case: transform array into a format such that, in a PDO insert statement, the array keys are the columns, and the array values are the SQL values. If this request duplicates others, I apologize. I haven't found one that works for me. In my example the parent array is Array[0], which gets inserted into one table, Array[1] are the children. They get iterated over and inserted into another table with fk_user_id as the foreign key.
Example insert: $sth = $dbh->prepare("INSERT INTO $table ($colData) VALUES ($valData)");
So, columns would be (key1, key2) and VALUES would be (:value1, :value2) and so on. I'm having all sorts of issues with multidimensions and extracting child nodes, etc, etc.
Sample array:
[INFO] Array ( [0] => Array ( [last_visit] => 1389393273.19 [first_visit] => 1389313338.69 [this_visit] => 1389393265.75 [latitude] => 37.7858352661 [longitude] => -122.406417847 [opted_out] => 0 [opted_in] => 0 [user_id] => 1 [locale] => en [device_maker] => unknown [device_model] => Simulator [os_platform] => iPhone OS [os_version] => 7.0.3 [modified] => 1389393273.19 [model_type] => tracker ) [1] => Array ( [0] => Array ( [view_count] => 1 [visit_timestamp] => 1389393265.63 [page_viewed] => home [page_id] => 320 [fk_user_id] => 1 [model_type] => page ) [1] => Array ( [view_count] => 2 [visit_timestamp] => 1389393265.64 [page_viewed] => contactView [page_id] => 321 [fk_user_id] => 1 [model_type] => page ) ) ) Solutions I've tried Remove parent - keep children, Remove key from associative array, Iterating over an array, Flatten array and others. I may be so deep in the code that I lost perspective of my data. It's been awhile since I worked this much with PHP, so my skills are in need of brushing up. Your help is greatly appreciated.