Created
March 7, 2013 15:34
-
-
Save yitsushi/5108882 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
echo ">>> Usage:\n"; | |
function do_it($callback) { | |
return $callback(null, true); | |
} | |
$result = do_it(function($error, $result) { | |
if ($error) { | |
echo "Error!\n"; | |
return false; | |
} | |
echo "Success\n"; | |
return true; | |
}); | |
var_dump($result); | |
echo "\n>>> Useful example:\n"; | |
$myArray = array(1, 2, 3, 5, 8, 13, 21); | |
$output = array_map(function($item) { | |
return $item * 2; | |
}, $myArray); | |
echo implode(", ", $output), "\n"; | |
/* Output | |
* ====== | |
* | |
* php callback.php | |
* >>> Usage: | |
* Success | |
* bool(true) | |
* | |
* >>> Useful example: | |
* string(23) "2, 4, 6, 10, 16, 26, 42" | |
* (clockwork) Ξ Development/Felveteli → vim callback.php | |
* (clockwork) Ξ Development/Felveteli → php callback.php | |
* >>> Usage: | |
* Success | |
* bool(true) | |
* | |
* >>> Useful example: | |
* 2, 4, 6, 10, 16, 26, 42 | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment