Monday, 11 November 2019




Summary
In this tutorial you looked at anonymous functions in PHP, and saw how to use them in various situations. You learned:
      • That an anonymous function is much like a regular function, except it has no name, and is an expression rather than a code construct.
      • How to assign an anonymous function to a variable, and how to call the anonymous function using the variable.

      • Ways to use inline anonymous functions as callbacks to create neater, tidier code.
      • How to create closures using anonymous functions. Closures are useful for many things, including making code more readable, avoiding global variables, and creating customisable callback functions.
I hope you found this tutorial helpful, and that you now feel confident creating and using anonymous functions in your PHP code. Have fun!
[Image credits:
Men,
megaphone,
gift boxes
via Shutterstock]FILED UNDER: PHP FUNCTIONS  


Reader Interactions

No comments:

Post a Comment