我知道我应该知道这一点,但我能得到它,
我需要得到总价
<?php
if (is_array(Yii::app()->session['cart']))
{
$totalQuantity = 0;
$totalPrice = 0;
foreach ( Yii::app()->session['cart'] as $value) {
$totalQuantity += $value['quantity'];
$totalPrice += $value['price'];
?>
<tr id="TDcartTable">
<td class="docName">
<?php echo $value['file']; ?>
</td>
<td>
£ <?php echo number_format($value['price'], 2); ?>
</td>
<td>
<?php echo $value['quantity']; ?>
</td>
<td>
£ <?php echo number_format(($value['quantity'] * $value['price']), 2); ?>
</td>
</tr>
<?php }
} ?>
</tr>
<tr>
<td class="column-title">
</td>
<td class="column-title">
</td>
<td class="column-title">
</td>
<td class="column-title">
<?php echo CHtml::encode(Yii::t('app', 'Total Quantity')); ?>: <?php echo $totalQuantity; ?>
</td>
<td class="column-title">
<?php echo CHtml::encode(Yii::t('app', 'Total')); ?>: £<?php echo number_format($totalPrice, 2); ?>
</td>
</tr>
当我这样做时,我会得到价格的总数,但我需要的是价格的总数(用数量计算),当我尝试这样做时
foreach ( Yii::app()->session['cart_values'] as $value) {
$totalQuantity += $value['quantity'];
$itemTotal = number_format(($value['price'] * $value['quantity']), 2);
$totalPrice += $itemTotal;
我得到了一些奇怪的数字。
感谢您的解释。