Skip to content

Instantly share code, notes, and snippets.

@jrmadsen67
Created November 10, 2012 22:35
Show Gist options
  • Save jrmadsen67/4052790 to your computer and use it in GitHub Desktop.
Save jrmadsen67/4052790 to your computer and use it in GitHub Desktop.
example of map_array() with "use" to pass in variable
function map_array()
{
$names = array('Foo', 'Bar', 'Baz', 'Buzz');
$tweeps = array();
foreach ($names as $name) {
$tmp = new StdClass;
$tmp->name = $name;
$tmp->age = rand(2,7);
array_push($tweeps, $tmp);
}
$check_string = 'age';
$str = "Mentioned by " . implode(", ", array_map(function($t) use ($check_string) { return $t->{$check_string}; }, $tweeps));
echo $str . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment