Skip to content

Instantly share code, notes, and snippets.

@pleckey
Created January 1, 2014 21:53
Show Gist options
  • Select an option

  • Save pleckey/8211883 to your computer and use it in GitHub Desktop.

Select an option

Save pleckey/8211883 to your computer and use it in GitHub Desktop.
Closures as array values
<?php
$array = array(
'first' => 'test',
'second' => function(){ return 'passed'; },
);
var_dump( $array );
foreach ( $array as $k => $v )
{
if ( is_callable( $v ) ) echo $v() . PHP_EOL;
else echo $v . PHP_EOL;
}
/*
* Output
*
array(2) {
'first' =>
string(4) "test"
'second' =>
class Closure#1 (0) {
}
}
test
passed
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment