I'm receiving arrays from an API that have a variable number of fields and I'm trying to get it into a table.
A sample object looks like this:
array
'silver' =>
array
'assets' =>
array
'Article' => float 2
'ROS_Medium_1' => float 37704
'ROS_Medium_2' => float 37711
'ROS_Medium_3' => float 37546
'ROS_Leaderboard_Footer' => float 37941
'ROS_Leaderboard_Infinite Scroll' => float 3636
'price' => float 375
'discount' => int 0
'banner_cpm' => float 12.79
'banner_sov' => float 0.0099
'content_cpm' => float 150
'content_sov' => float 0.0028
'fixed_cpm' => float 0
'blended_cpm' => float 26.26
'gold' =>
array
'assets' =>
array
'Article' => float 2
'ROS_Leaderboard' => float 15212
'ROS_CCF' => float 1
'ROS_Halfpage' => float 15212
'ROS_Medium_1' => float 12459
'ROS_Medium_2' => float 12476
'ROS_Medium_3' => float 12476
'ROS_Leaderboard_Footer' => float 12390
'ROS_Leaderboard_Infinite Scroll' => float 1239
'price' => int 500
'discount' => int 0
'banner_cpm' => float 18.84
'banner_sov' => float 0.008
'content_cpm' => float 150
'content_sov' => float 0.0028
'fixed_cpm' => float 0
'blended_cpm' => float 29.8
The number of columns equals the number of top level arrays (so, silver and gold here)
The number of top-level arrays can vary, and the assets sub-array can vary from array to array (notice how the "gold" array has more assets in the sample code). There should be a row for each asset, and each other key in the array.
What would be the cleanest way to get all this information into a table-ready format? As far as I can tell, the first step would be to make an array of all the unique assets. But then without clunkily nesting a bunch of foreach loops, I'm not sure where to go from here.
The desired output will look something like http://i.imgur.com/m0IJpUj.png