I am using the following foreach loop to populate a new array with filtered data.
foreach ($aMbs as $aMemb) {
$ignoreArray = array(1, 3);
if (!in_array($aMemb['ID'], $ignoreArray)) {
$aMemberships[] = array($aMemb['ID'] => $aMemb['Name']);
}
}
The problem is that it is producing a 2-dimensional array, but I want to have a flat, associative array.
If $aMbs had the following data:
[
['ID' => 1, 'Name' => 'Standard'],
['ID' => 2, 'Name' => 'Silver'],
['ID' => 3, 'Name' => 'Gold'],
['ID' => 4, 'Name' => 'Platinum'],
['ID' => 5, 'Name' => 'Unobtainium'],
]
The desired output would be:
[
2 => 'Silver',
4 => 'Platinum',
5 => 'Unobtainium',
]
How can I achieve this?
'1' => 'Standard'would exist in the output if only elements with non-blacklisted keys are pushed into the output array.