Skip to content

Instantly share code, notes, and snippets.

@blar
Created March 15, 2014 18:17
Show Gist options
  • Select an option

  • Save blar/9571597 to your computer and use it in GitHub Desktop.

Select an option

Save blar/9571597 to your computer and use it in GitHub Desktop.
<?php
$context = 'foobar';
$closure = function($value, $index) use($context) {
var_dump($context);
var_dump($value * 2);
};
unset($context);
foreach(array(23, 42) as $index => $value) {
$closure($value, $index);
}
string(6) "foobar"
int(46)
string(6) "foobar"
int(84)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment