Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created March 7, 2013 15:34
Show Gist options
  • Save yitsushi/5108882 to your computer and use it in GitHub Desktop.
Save yitsushi/5108882 to your computer and use it in GitHub Desktop.
<?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