2
+----------------------------------------------------------
3
* use 用法
4
+----------------------------------------------------------
5
* @access getTotal
6
+----------------------------------------------------------
7
* @params Array $products_costs 数字数组
8
* @params float $tax 系数
9
+----------------------------------------------------------
10
* @return float
11
+----------------------------------------------------------
12
* log name date note
13
* @author hxl 初始化
14
* @edit
15
+----------------------------------------------------------
16
**/
17
function
getTotal(
$products_costs
,
$tax
) {
18
$total
= 0.00;
19
/* 声明匿名函数
20
* use 作用为给外部引用($tax 和$total)起别名
21
*/
22
$callback
=
function
(
$pricePerItem
)
use
(
$tax
, &
$total
) {
23
$total
+=
$pricePerItem
* (
$tax
+ 1.0);
24
};
25
//用$products_costs 中元素依次作为参数调用$callback 函数
26
array_walk(
$products_costs
,
$callback
);
27
return
round(
$total
, 2);
28
}
29
30
getTotal(
array
(1,2,3,45,66,2),4);