I want to insert the values from the first array inside the second array, where the key's name is [cost]:
$newcosts
Array (
[0] => 52.68
[1] => 7414.68
[2] => 2471.56
)
$mainarray
[0] => Array (
[id] => 2
[date] => 15.12.2020
[cost] => 60.00
)
[1] => Array (
[id] => 1
[date] => 22.12.2020
[cost] => 60.00
)
[2] => Array (
[id] => 3
[date] => 24.12.2020
[cost] => 22.00
)
I tried the following:
foreach ($mainarray as $key => $value) {
$values[] = $value['cost'];
$new_array[] = str_replace($values, $newcosts, $value);
}
for some reason, this is not showing the right data and sometime they get repeated. this is an example:
[0] => Array (
[id] => 2
[date] => 15.12.2020
[cost] => 52.68
)
[1] => Array (
[id] => 1
[date] => 22.12.2020
[cost] => 52.68
)
[2] => Array (
[id] => 3
[date] => 24.12.2020
[cost] => 2471.56
)
Hope someone could help me on that. Thank you very much!