Created
April 22, 2022 16:36
-
-
Save marrek13/f57b1b526efe886a911d7e68b327a59a to your computer and use it in GitHub Desktop.
Fold PHP
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 | |
function fold($array, $callback, $initial=null) | |
{ | |
$acc = $initial; | |
foreach($array as $a) | |
$acc = $callback($acc, $a); | |
return $acc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment