Here is array #1
[
['first' => 'LightSpeed', 'last' => 'Administrator'],
['first' => 'Tyler', 'last' => 'Nichol']
]
Here is array #2
[
'I-10' => ['user' => 2, 'total' => 46.64],
'I-11' => ['user' => 2, 'total' => -46.64]
]
I just want to add [total] => $value to the first array so it looks like.
[
['first' => 'LightSpeed', 'last' => 'Administrator', 'total' => 46.64],
['first' => 'Tyler', 'last' => 'Nichol', 'total' => -46.64]
]
I'm pretty sure that I need array_push()
, but I'm not sure how to loop it.
It's a bit low tech, but I'd just loop through your array and insert the total item. Assuming you're just matching to the second array on the position of the items in the arrays:
$vals = array_values($arr2);
foreach($arr1 as $i=>$item) {
$arr1[$i]['total'] = $vals[$i]['total'];
}