直接代碼,使用場景:現(xiàn)在的代碼:$gifts=$this->get_list();$gifts=array_filter($gifts,function($v)use($customer_id){returncall_user_func(array($this,'gift_selector'),$v,$customer_id);});如果:$gifts=$this->get_list();$gifts=array_filter($gifts,($this,'gift_selector'));$gift是可以作為默認參數(shù)傳入$this->gift_selector(),但是外部變量$customer_id怎么傳入呢?當然,closure的時候可以使用use($customer_id)這個是知道的,不過在這里想把回調(diào)函數(shù)拿出來寫,因為寫成closure太長了。
PHP函數(shù)回調(diào)參數(shù)如何在回調(diào)函數(shù)內(nèi)使用外部參數(shù)
富國滬深
2019-04-16 16:46:23