问题描述
可能重复:结果
通过SUM
我工作的一个批发公司创建的购物推车。我将创建后来也发票。这是同样的道理。
I'm working on creating shopping-cart for a wholesale company. And i'll create also invoice later. It's same logic.
首先,我乘的一揽子贷款(包)*一揽子贷款adeti(包装数量)*fiyatı(价格)我写它在列表的末尾。现在我要计算增值税。主要的问题是,我们并不确切地知道以前的增值税率。
Firstly, i multiply paket (package) * paket adeti (package quantity) * fiyatı (price) And i wrote it at the end of list. Now i have to calculate vat. The main problem is we don't know vat ratios exactly before.
可能存在3种不同的增值税率。 (这取决于哪个客户选择产品)可以是一个。
May be there exist 3 different vat ratios. (it depends on the products which customer selects) May be one.
我做了大桶的数组
$vats[] = array($row['vat'], $row['wholesaleprice'] - $wholesaleprice);
结果就是这样
Array (
[0] => Array ( [0] => 18 [1] => 1,07 )
[1] => Array ( [0] => 8 [1] => 0,44 )
[2] => Array ( [0] => 8 [1] => 0,67 )
[3] => Array ( [0] => 18 [1] => 0,55 )
[4] => Array ( [0] => 18 [1] => 0,19 )
[5] => Array ( [0] => 8 [1] => 0,48 )
[6] => Array ( [0] => 18 [1] => 2,59 )
[7] => Array ( [0] => 8 [1] => 0,15 )
[8] => Array ( [0] => 18 [1] => 12,97 )
)
我要总结通过比增值税组...
I have to sum vat group by ratios...
我要像显示
增值税(18%),136,26 TL
增值税(8%)16,90 TL
增值税(1%)9,28¥
VAT (%18) 136,26 TLVAT (%8) 16,90 TLVAT (%1) 9,28 TL
我该怎么办,在快捷方式。我已经检查数组功能。但我无法找到任何有用的东西。
How can i do that in shortcut. I've check array functions. But i couldn't find anything useful.
购物车: http://i.stack.imgur.com/DDsCq.png一>
推荐答案
尝试是这样的:
<?php
$data = Array (
Array ( 0 => '18', 1 => '1,07' ),
Array ( 0 => '8', 1 => '0,44' ),
Array ( 0 => '8', 1 => '0,67' ),
Array ( 0 => '18', 1 => '0,55' ),
Array ( 0 => '18', 1 => '0,19' ),
Array ( 0 => '8', 1 => '0,48' ),
Array ( 0 => '18', 1 => '2,59' ),
Array ( 0 => '8', 1 => '0,15' ),
Array ( 0 => '18', 1 => '12,97' )
);
// predefine array
$data_summ = array();
foreach ( $data as $value ) {
$data_summ[ $value[0] ] = 0;
}
foreach ( $data as $list ) {
$number = str_replace( ",", ".", $list[1] ) * 1;
$data_summ[ $list[0] ] += (float)$number;
}
?>
输出 $ data_summ
:
Array
(
[8] => 1.74
[18] => 17.37
)
如果我理解正确。
这篇关于PHP数组心集团通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!