Returning a value from an anonymous function

Anonymous functions were added to php in version 5.3, and are most often used for assigining a function to a variable to be used later as a callback. They also are useful for declaring limited-use or one-time-use functions without declaring them in the global space.

Sometimes it is desired to receive a value BACK from an anonymous function, and how to do that is not intuitive.

First, let's look at how it works with a typical function:


Add new comment


  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Missing filter. All text is removed
CAPTCHA This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.