I'm trying to create HTML table from multidimensional php array, however it is partially designed. Can some one please take a loom and advise.
This is how my Multidimensional array looks like:
array(2) { [0]=> array(3)
{ ["Objective"]=> string(11) "Conversions"
["Top Performing Targeting Group"]=> array(2) { [0]=> string(48) "Female (27.74% cheaper )^25-34 (27.74% cheaper )" [1]=> string(48) "Female (22.52% cheaper )^18-24 (22.52% cheaper )" }
["Top Performing Placement"]=> array(1) { [0]=> string(52) "Mobile Feed (13.53% cheaper)^iPhone (13.53% cheaper)" } }
[1]=> array(3)
{ ["Objective"]=> string(10) "Page Likes"
["Top Performing Targeting Group"]=> array(0) { }
["Top Performing Placement"]=> array(2) { [0]=> string(50) "Mobile Feed (1.42% cheaper)^iPhone (1.42% cheaper)" [1]=> string(51) "Mobile Feed (1.71% cheaper)^Android (1.71% cheaper)" } } }
My HTML table code looks like:
function generateTable2($associative_array){
echo '<table width="620" class="optimization_table"><thead><tr><th>';
echo implode('</th><th>', array_keys(current($associative_array)));
echo '</th></tr></thead><tbody>';
foreach ($associative_array as $row=>$value){
echo "<tr><td>";
if(is_array($value)) {
foreach ($value as $k => $v) {
if(is_array($v))
{
foreach ($v as $key => $value) {
//explode("^",$v)
echo "</td>";
print_r($key);
print_r($value);
//explode("^",$k)[2]
# code...
}
}
//echo implode('</td><td>', $v);
else echo "$v"."</td><td>";
}
}
//echo implode('</td><td>', $value);
//else echo implode('</td><td>', $value);
else echo "$value"."</td><td>";
}
echo '</tbody></table>';
}
