Parameter passing of each() in paginate of TP5 paging function


When using each(), only local variables can be used in each(). When using external variables, errors of undefined variables will be reported. However, sometimes we have to use external variables, so we need to think about the problem of time scope. However, if using global global, though no errors are reported, it will print out null, so we finally use ituse To solve this problem, if you need to modify the value of a variable in a function, you will find that the value of the variable has changed in the function, but the value of the variable outside the function has not changed. If you want to change the value of the variable inside and outside the function at the same time, add “&” before use.

$list = Db::view('drugall')
            ->view('drug_class','id drugclass_id','drugall.drugclass_id =')
            ->(function ($item,$key) use(&$userId)
                $item['time'] = Db::view('drug','createtime')
                    ->view('draft_user','draftkind',' = draft_user.draftId')
                return $item;
        return $list;


Recommended Today

A text to clarify the context in JavaScript

background This article is part of “in 2019, after reading this one, I will no longer be afraid of the front-end interview” Refer to what I wrote beforeBlogAnd extradata, share it to you, hope to bring some to youInspiration and help。 For reprint, please contact the author for permission. text contextIt is an important concept […]