/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php $multiply = function($multiplier) { return function($x) use ($multiplier) { return $x * $multiplier; }; }; // $mul5 now contains a function that returns a number multiplied by 5 $mult5 = $multiply(5); // $mul7 contains a function that returns a number multiplied by 7 $mult7 = $multiply(7); echo $mult5(5); echo $mult7(5); // Output- // 25 // 35 ?>
URL: http://www.codediesel.com/php/anonymous-functions-in-php