0
有沒有辦法從一個匿名函數中繼承多個變量?我知道只是繼承一個數組,但我很好奇,如果有另一種方式來繼承變量,而不是使用數組。在匿名函數中繼承多個變量
也許是這樣的:
function($arg) use ($inherited1, $inherited2){
// access the $inherited1 and $inherited2 variables directly
}
有沒有辦法從一個匿名函數中繼承多個變量?我知道只是繼承一個數組,但我很好奇,如果有另一種方式來繼承變量,而不是使用數組。在匿名函數中繼承多個變量
也許是這樣的:
function($arg) use ($inherited1, $inherited2){
// access the $inherited1 and $inherited2 variables directly
}
你可以這樣做
$inherited1 = '1';
$inherited2 = '2';
$example = function($arg) use (&$inherited1, &$inherited2){
// access the $inherited1 and $inherited2 variables directly
var_dump($arg . $inherited1 . $inherited2);
}
$example('arg');
哈真的這樣工作:d – Skeletor
簡直就是一個天大NO – Alice