Re: array_map : to call a method on all objects
DigitalBase write:
> Hi,
>
> I am trying to call a method on all objects in an array.
>
> What i am doing now ::
>
> $groups = $user->getGroups();
> $newarray = array();
> foreach ($groups as $group) {
> $newarray[] = $group->getId();
> }
>
> I want to use a core feature of php to achieve this something like :
>
> $groups = $user->getGroups();
> array_map(array( ???? ,"getId"),$groups);
$idList=array_map(create_function('$group','return
$group->getId();'),$groups);
|