Core PHP

Anonymous Functions

This PHP code is an example program that demonstrates how to write anonymous functions.

AnonymousFunctions.php

<?php

  // This is an anonymous function that is assigned to a variable.
  $fnPrint = function(string $sName) {
    echo "Hello ".$sName."!<br />";
  };

  // Call the function with an argument.
  $fnPrint("XoaX.net");

?>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.