我有一个页面显示我当天的订单,但现在我想对 7 / 15 和 30 天前的值进行计数和求和(如果可能在列表中),或者在此步骤中仅计数/求和: <strong>Soon</strong>$pedido->valor_pedido是我从订单中获得的价值$pedido->id从订单中获得的 id,我用来计数。我的代码:<div class="row"><?php$totalPedido = 0;$contagPedido = 0;foreach ($pedidos as $pedido) { $totalPedido += $pedido->valor_pedido; // sum day orders $contagPedido += count($pedido->id); //count day orders}?> <div class="span12"> <!-- Widgets --> <ul class="widgets"> <!-- Basic widget item --> <li class="span3"> <span class="widget-label"><span class="awe-star"></span> This Week</span> <strong>Soon</strong> </li> <!-- /Basic widget item --> <!-- Clickable widget item --> <li class="span3"> <span class="widget-label"><span class="awe-star"></span> Totay</span> <strong>R$ <?= ConverteReal($totalPedido) ?></strong> </li> <!-- /Clickable widget item --> <!-- Widgets with graphs --> <li class="span3"> <span class="widget-label"><span class="awe-star"></span> Orders this week</span> <strong>Soon</strong> </li> <li class="span3"> <span class="widget-label"><span class="awe-star"></span> Orders today</span> <strong><?= $contagPedido ?></strong> </li> <!-- /Widgets with graphs --> </ul> <!-- /Widgets --> </div></div>
1 回答
小怪兽爱吃肉
TA贡献1852条经验 获得超1个赞
根据 PHP 手册,count()将用于获取数组中所有元素的计数
如果$pedido->id是唯一ID,则可以获取$pedidos数组的计数,例如
<?
$contagPedido = count($pedidos); // total no of orders
foreach ($pedidos as $pedido) {
$totalPedido += $pedido->valor_pedido; // sum day orders
}
?>
- 1 回答
- 0 关注
- 212 浏览
添加回答
举报
0/150
提交
取消