Skip to content

Instantly share code, notes, and snippets.

@sineld
Created November 27, 2012 07:12
Show Gist options
  • Select an option

  • Save sineld/4152884 to your computer and use it in GitHub Desktop.

Select an option

Save sineld/4152884 to your computer and use it in GitHub Desktop.
Using Closures with use and new array style @ Php 5.4
<?php
$message = ['Good Morning', 'Good Afternoon', 'Good Evening', 'Good Night'];
$greetingsTo = function($to) use($message){
return $message[rand(0,count($message)-1)].' '.$to;
};
echo $greetingsTo('Tuana Şeyma');
// Good Morning Tuana Şeyma
// Good Afternoon Tuana Şeyma
// Good Evening Tuana Şeyma
// Good Night Tuana Şeyma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment