Just for curiosity (I know it can be a single line foreach
statement), is there some PHP array function (or a combination of many) that given an array like:
Array (
[0] => stdClass Object (
[id] => 12
[name] => Lorem
[email] => lorem@example.org
)
[1] => stdClass Object (
[id] => 34
[name] => Ipsum
[email] => ipsum@example.org
)
)
And, given 'id'
and 'name'
, produces something like:
Array (
[12] => Lorem
[34] => Ipsum
)
I use this pattern a lot, and I noticed that array_map
is quite useless in this scenario cause you can't specify keys for returned array.