PHP foreach function performance

Viewed 4532

Does anyone know if doing this

foreach ($user->getFriends() as $friend) {
  // Do something.
}

Causes PHP to call the function getFriends() on the user object multiple times and thus would this be more efficient?

$friends = $user->getFriends();
foreach ($friends as $f) {
 // Do something.
}
4 Answers
Related