Afficher un message
Vieux 17/06/2008, 11h33   #4
Alexey Kulentsov
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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);
  Réponse avec citation
 
Page generated in 0,04268 seconds with 9 queries