Let's say I have a PHP array:
$array1 = array(
'protein' => array('PROT', 100, 150),
'fat' => array('FAT', 100, 250),
'carbs' => arary('CARBS', 10, 20)
);
$array2 = array(
'vitaminA' => array('vitA', 1, 2),
'vitaminB' => array('vitB', 1, 2),
'vitaminC' => arary('vitC', 1, 2)
);
Now I want a combined array of those nutrients (something like array_merge()), but I only need the keys, not the values themselves.
So either this:
$combined = array(
'protein' => NULL,
'fat' => NULL,
'carbs' => NULL,
'vitaminA'=> NULL,
'vitaminB'=> NULL,
'vitaminC'=> NULL
);
OR
$combined = array('protein', 'fat', 'carbs', 'vitaminA', 'vitaminB', 'vitaminC');
I can do this manually with a foreach loop, but I was hoping there's a function which would make this process fast and optimized.
array_merge(array_keys($array1),array_keys($array2))