Let’s say I’ve got an array of objects from class Users.
Class Users contain the property email.
How can I make an array of the email property from the array of user objects?
Is there a better/faster way than:
$emails = array();
foreach($users as $user) {
$emails[] = $user->email;
}
Looks like a foreach loop is the fastest. Syntax is a matter of taste, I guess.
EDIT
As I said in my response to David’s post, I have in fact benchmarked this.
Gives pretty solid results.
I don’t know if this is because I am on a windows machine at the moment, but for me, array_map is definetedly NOT faster. Not trying to mislead anyone here.