Created
November 10, 2012 22:35
-
-
Save jrmadsen67/4052790 to your computer and use it in GitHub Desktop.
example of map_array() with "use" to pass in variable
This file contains 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
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