本文整理汇总了PHP中Arr::sum方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::sum方法的具体用法?PHP Arr::sum怎么用?PHP Arr::sum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::sum方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_sum_multi_array
/**
* Tests Arr::sum()
*
* @test
*/
public function test_sum_multi_array()
{
$arr_multi = array(array('name' => 'foo', 'scores' => array('sports' => 5, 'math' => 20)), array('name' => 'bar', 'scores' => array('sports' => 7, 'math' => 15)), array('name' => 'fuel', 'scores' => array('sports' => 8, 'math' => 5)), array('name' => 'php', 'scores' => array('math' => 10)));
$expected = 50;
$test = \Arr::sum($arr_multi, 'scores.math');
$this->assertEquals($expected, $test);
$expected = 20;
$test = \Arr::sum($arr_multi, 'scores.sports');
$this->assertEquals($expected, $test);
}
示例2: total_price
/**
* Calculate order total price
* We will return sum of all kind of different
* prices that affect total price
*
* @return type
*/
public function total_price()
{
$total_price[]['price'] = $this->shipping_price;
$total_price[]['price'] = $this->total_price;
return \Arr::sum($total_price, 'price') - $this->discount_amount;
}