Lets say I have a multi-dimensional array like this :
$results = array(
0 => array(
'fruit' => 'apple',
'colour' => 'green',
'amount' => 50
),
1 => array(
'fruit' => 'orange',
'colour' => 'orange',
'amount' => 25
),
2 => array(
'fruit' => 'banana',
'colour' => 'yellow',
'amount' => 7
)
);
And I want to create a new multi-dimensional array only using specific objects :
$newarray = array(
0 => array(
'fruit' => 'apple',
'amount' => 50
),
1 => array(
'fruit' => 'orange',
'amount' => 25
),
2 => array(
'fruit' => 'banana',
'amount' => 7
)
);
How would I do this? I've read a few different things and it seems like array_map or array_column might be the answer but I haven't found an example that fits my situation.
I've got as far as :
$newarray = array();
foreach ($results as $result) {
if (!empty($result['fruit'])) {
// create new array here but how do I specify the key => values?
}
}
->? you need to use[]in arrays=>, I'm talking about using->to access elements in arrays (check the edit history)