PHP use() function for scope?

前端 未结 2 957
春和景丽
春和景丽 2020-12-10 13:24

I have seen code like this:

function($cfg) use ($connections) {}

but php.net doesn\'t seem to mention that function. I\'m guessing it\'s re

2条回答
  •  被撕碎了的回忆
    2020-12-10 14:00

    It is telling the anonymous function to make $connections (a parent variable) available in its scope.

    Without it, $connections wouldn't be defined inside the function.

    Documentation.

提交回复
热议问题