I have an array that is built as follows
foreach($details as $data)
{
$loans[] = [
'name' => 'Details',
[
'name' => 'id',
'value' => 1
],
[
'name' => 'Date',
'value' => '2015'
],
[
'name' => 'Purpose',
[
'name' => 'Code',
'value' => 123
]
],
getFees($data)
];
}
I need to use the fees from the getFees function and have those values set at the same level as the 'name' => 'Details' above.
private function getFees($data)
{
foreach($data as $item){
$values[] = [
'name' => 'type',
'value' => 'Interest'
];
}
return $values;
}
So the above produces the following:
Array
(
[name] => Details
[0] => Array
(
[name] => Details
[0] => Array
(
[name] => id
[value] => 1
)
[1] => Array
(
[name] => Date
[value] => 2015
)
[2] => Array
(
[name] => Purpose
[0] => Array
(
[name] => Code
[value] => 123
)
)
[3] => Array
(
[0] => Array
(
[name] => Type
[value] => Interest
)
)
)
)
But I don't want that [3] array to be another level deeper, I simply want:
Array
(
[name] => Details
[0] => Array
(
[name] => Details
[0] => Array
(
[name] => id
[value] => 1
)
[1] => Array
(
[name] => Date
[value] => 2015
)
[2] => Array
(
[name] => Purpose
[0] => Array
(
[name] => Code
[value] => 123
)
[3] => Array
(
[name] => Type
[value] => Interest
)
)
)
Clearly I'm missing something - if i try to do array_merge, outside the loop, then the fees array is outside the Details array.
If the getFees function only sets the array to one single element, then it works fine, but I need to allow for multiple elements, hence the $values[] assignment.
How do i produce the array as required above ?