Possible duplicate:
In Php 5.3.0, what is the "Use" identifier function? Should a system programmer use it?
I studied Closures in PHP, and that is what caught my attention:
public function getTotal($tax) { $total = 0.00; $callback = 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); }
And someone, please give me an explanation about using use in this code.
function ($quantity, $product) use ($tax, &$total)
When I look at use in PHP, it finds the use keyword, where it is used in namespaces, but here it looks different.
Thank.
closures php anonymous-function
Tarik Jun 12 '11 at 6:25 2011-06-12 06:25
source share