Is there a built in function to do the following?
$a[] = $b[0]['foo'];
$a[] = $b[1]['foo'];开发者_StackOverflow中文版
$a[] = $b[2]['foo'];
etc..
I realize I can do something like the following:
foreach($b as $c)
{
$a[] = $c['foo'];
}
But I am really just curious if there is some built in array function that will do this. Thanks.
In short: no.
In long: Maybe ;) Its because its not "directly built-in"
With PHP5.3
$a = array_map (function ($entry) {
return $entry['foo'];
}, $b);
or before
$a = array_map (create_function ('$entry', 'return $entry[\'foo\'];'), $b);
At least for the second solution I would prefer the foreach
-loop ;)
Perhaps the array_map function
$func = function($value) {
return $value['foo'];
};
print_r(array_map($func, $a));
精彩评论