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

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

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

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 -