What use keyword do in closures in php

后端 未结 2 1552
太阳男子
太阳男子 2020-12-21 23:17

I found code like this and can\'t find what it does

$callback = function ($pricePerItem) use ($tax, &$total) {
    $total += $pricePerItem * ($tax + 1.0)         


        
2条回答
  •  一生所求
    2020-12-21 23:41

    Check this - http://php.net/manual/en/functions.anonymous.php, if an anonymous function wants to use local variables (for your code, it's $tax and $total), it should use use to reference them.

提交回复
热议问题