-1
我在循環內部有一個Laravel ->each()
函數。從'每個'函數的回調函數中訪問變量
我希望能夠從每個函數中獲取循環變量。
foreach ($stringsArray as $string) {
if (!empty($string)) {
DBModel::all()->each(function (DBModel $model) {
global $string;
// $string at this point is nothing/undefined
我怎樣才能從->each()
函數內訪問$string
?
這是使用laravel 4.2。
與當前代碼$string
是不確定的(有或沒有global
指令)。
的可能重複使用它:([PHP使用它以外的計算變量的回調函數] https://stackoverflow.com/questions/4588714/PHP-回調函數使用變量計算-外的-它) –