This is my array and I want to set this array in table format and I want to set first row as show below:
$_tierPrices = Array
(
Array
(
"price_qty" => "4",
"price" => "143.00",
"savePercent" => "8"
),
Array
(
"price_qty" => "12",
"price" => "133.0000",
"savePercent" => "15"
),
Array
(
"price_qty" => "20",
"savePercent" => "18",
"price" => "128.0000"
),
Array
(
"price_qty" => "40",
"savePercent" => "21",
"price" => "123.0000"
)
);
4 | 12 | 20 | 40 |
4 - 11 | 12 - 19 | 20 - 39 | 40+ |
Try this:
Tier Price Array
<?php
$_tierPrices = array (
array
(
"price_qty" => "4",
"price" => "143.00",
"savePercent" => "8"
),
array
(
"price_qty" => "12",
"price" => "133.0000",
"savePercent" => "15"
),
array
(
"price_qty" => "20",
"savePercent" => "18",
"price" => "128.0000"
),
array
(
"price_qty" => "40",
"savePercent" => "21",
"price" => "123.0000"
)
);
?>
Tier Price Table
<table>
<tr><td>Header</td></tr>
<?php $_qtyRow = '<tr>'; ?>
<?php $_priceRow = '<tr>'; ?>
<?php $_saveRow = '<tr>'; ?>
<?php
$size = count($_tierPrices);
foreach($_tierPrices as $index => $_tierPrice) {
if($index < $size-1) {
$_qty = $_tierPrice['price_qty'] . ' - ' . ($_tierPrices[$index+1]['price_qty'] - 1);
} else {
$_qty = $_tierPrice['price_qty'] . '+';
}
$_qtyRow .= '<td>'.$_qty.'</td>';
$_priceRow .= '<td>'.$_tierPrice['price'].'</td>';
$_saveRow .= '<td>'.$_tierPrice['savePercent'].'</td>';
}
$_qtyRow .= '</tr>';
$_priceRow .= '</tr>';
$_saveRow .= '</tr>';
echo $_qtyRow;
echo $_priceRow;
echo $_saveRow;
?>
<tr><td>Footer</td></tr>
</table>
I hope this will help.