I have the following array:
$inventory = [
'Apples' => ['Golden Delicious', 'Granny Smith','Fuji'],
'Oranges' => ['Valencia', 'Navel', 'Jaffa']
];
What I would like to end up with is an array with the following:
['Apples','Oranges']
I can do:
$fruits = [];
foreach ($inventory as $key => $value) {
$fruits[] = $key;
}
I am trying to educate myself on the use array_map, I tried:
$fruits[] = array_map('fruitTypes', $inventory);
function fruitTypes($item) {
echo key($item)."\n";
echo array_key_first($item)."\n";
echo $item[0]."\n";
//return something that will give me 'Apples' followed by 'Oranges'
}
But I am getting this:
0
0
Golden Delicious
0
0
Valencia
Any ideas?
array_keysin conjuction with array map. the keys in array map is not accessible out of the box