The anonymous functions are special types of function that have no specified name, hence being anonymous. They are also known as closures.

Syntax for an anonymous function

<?php
    $var = function() 
    {
        // ... code here
    }
?>

Example of an anonymous function as a closure to a variable

Example showing how to inherit variables from parent scope

 

›› go to examples ››