KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: In Php 5.3.0 what is the Function “Use” Identifier ? Should a sane programmer use it? I've been examining the Closures in PHP and this is what took 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 somebody please give me an explanation about the usage of use in this code. function ($quantity, $product) use ($tax, &$total) When I search use in PHP, it finds use keyword where it is used in namespaces but here it looks different. Thanks.
Tags (comma-separated)
Save Edits
Cancel