Created
January 1, 2014 21:53
-
-
Save pleckey/8211883 to your computer and use it in GitHub Desktop.
Closures as array values
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 | |
| $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