I have an array with following format:
Array
(
[0] => Array
(
[Push to Web] => Yes
[attribute_set] => laminate_flooring
[category] => Accessories/Underlay
[name] => Under Pad Feather Light Foam
[sku] => 123-1028
[description] => Floor Underlayment Feather Light (Vapour Barrier) 200 Sqft/Roll
[short_description] => Floor Underlayment Feather Light (Vapour Barrier) 200 Sqft/Roll
[image] => 123-1028.jpg
[gallery_Image] => 9095307460638-424-424.jpg
[price] => 0.24
[qty_ca] => 16
[weight] => 3
[meta_description] => 51-1001
[meta_title] => Under Pad Feather Light Foam
[status] => 1
[flooring_coverage] => 200
[is_flooring_product] => 1
[web_price_comparative] => 0.31
)
[1] => Array
(
[Push to Web] => Yes
[category] => Accessories
[name] => Vent Maple Flush 4x10
[sku] => 089-1000
[description] => Vent Flush Mount Maple 4 x 10
[short_description] => Vent Flush Mount Maple 4 x 10
[image] => 089-1000.jpg
[price] => 17.05
[qty_ca] => 63
[qty_us] => 41
[meta_description] => 10-1023
[meta_title] => Vent Maple Flush 4x10
[status] => 1
[flooring_coverage] => 1
[min_order_qty] => 400
[web_price_comparative] => 22.16
)
)
I have to print the data in the table so that each key of array is printed as column header and the value as column data. That means Push to Web, attribute_set etc will be header and Yes, laminate_flooring will be data respectively.
I wrote the following but its not working.
$row = 0;
$table = '<table border="1" id="datatable">';
foreach($data as $value){
$table .= '<tr>';
if ($row == 0) {
foreach($value as $innerkey=>$innervalue){
$table .= '<td>'.$innerkey.'</td>';
}
}
$table .= '</tr><tr>';
foreach($value as $innerkey=>$innervalue){
$table .= '<td>'.$innervalue.'</td>';
}
$table .= '</tr>';
$row++;
}
$table .= '</table>';
print_r($table);
The output of the table should be as follows:
First problem is the header row is continue printing only upto avalable data in first data row. Secondly If any data cell is unavailable then it is filled by next cell data. but it is supposed to be remain bank cell. Please help me to sort out the problem. Thanks in advance