I have a multi dimensional array like this:
[0] =>
['batch_id'] => '1'
['some_stuff'] => 'values'
[0] =>
['unit_id'] => '12'
['some_stuff'] => 'values'
[1] =>
['unit_id'] => '41'
['some_stuff'] => 'values'
This comes from an external API, so I have no control over the original formatting of the array.
What would be the preferred (least overhead) way to take all the 'unit_id' and 'batch_id' fields, remove them from the group of values about the item, and assign that value to the item's key?
What I've tried (and works, but I want to find something cleaner):
public function fixArray($batches) {
$batchfix = array();
foreach($batches as $batch) {
$unitfix = $array;
$batch_temp = $batch;
array_shift(array_shift($batch_temp)); // Get rid of id details
foreach($batch_temp as $unit)
$unittemp = $unit;
array_shift($unittemp);
$unitfix[$unit['unit_id']] = $unittemp;
$batchfix[$batch['batch_id']] = $batch;
}
return $batchfix;
}
Any suggestions?