I have an arrays that looks like this:
Array
(
[0] => stdClass Object
(
[food] => Pizza
[music] => Rock
[color] => blue
[name] => John
)
[1] => stdClass Object
(
[food] => Toast
[music] => Jazz
[color] => yellow
[name] => Greg
)
[2] => stdClass Object
(
[food] => Steak
[music] => Classical
[color] => green
[name] => Steve
)
[3] => stdClass Object
(
[food] => Cake
[music] => Blues
[color] => red
[name] => Peter
)
)
How do I create a new array where I combine some of the content to new key => value pairs, like Peter => Cake?
I already managed to use some values, but they are not connected to the keys:
$myArr = *The array posted above*
$newArray = array();
foreach ( $myArr as $arr ) {
array_push( $newArray, $arr->food );
}
That would be something like:
Note that duplicate names get overwritten with the last occurrence.