Created
July 1, 2019 14:02
-
-
Save novia713/c5a49c9f46db4b558a3902a00c5b5ba1 to your computer and use it in GitHub Desktop.
[PHP FUNCTIONAL PROGRAMMING PATTERNS] Function builder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$discount = function($percent){ | |
return function($price) use ($percent){ | |
return ($price - ($price * $percent * 0.01)); | |
}; | |
}; | |
$half_off = $discount(50); | |
echo $half_off(500); | |
$quarter_off = $discount(25); | |
echo $quarter_off(500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment