在PHP中,什么是闭包,为什么它使用“use”标识符?
PHP 5.3.0
public function getTotal($tax){
$total = 0.00;
$callback =
/* This line here: */
function ($quantity, $product) use ($tax, &$total)
{
$pricePerItem = constant(__CLASS__ . "::PRICE_" .
strtoupper($product));
$total += ($pricePerItem * $quantity) * ($tax + 1.0);
};
array_walk($this->products, $callback);
return round($total, 2);}
千巷猫影
哈士奇WWW
潇湘沐
随时随地看视频慕课网APP