php - How to use variables in callback functions? -


(how) is it possible to use a variable within a callback function? For example, I want to use the $ add variable inside my callback function:

  private function addToWord ($ add) {return preg_replace_callback ('/ ([Az]) + / i ', function ($ word, $ add) {return word $. $ Add;}, $ this- & gt; text); }    

You can use here:

  Private function addToWord ($ add) {return preg_replace_callback ('/ ([az]) + / i', function ($ word) usage ($ add) {return $ word [1]. $ Add;}, $ this- & Gt; text); }    

Comments

Popular posts from this blog

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -

jasper reports - How to center align barcode using jasperreports and barcode4j -

django - CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False -