Combine bidimensional array with another single dimension array in php -
i want combine 2 arrays keeping keys digit order.
here's first array:
array:3 [▼ 0 => array:1 [▼ "nombre" => "pilsener" ] 1 => array:1 [▼ "nombre" => "golden" ] 2 => array:1 [▼ "nombre" => "suprema" ] ]
and here's other array:
array:3 [▼ 0 => "6" 1 => "5" 2 => "1" ]
what want is:
array:3 [▼ 0 => array:1 [▼ "nombre" => "pilsener" "cantidad" => "6" ] 1 => array:1 [▼ "nombre" => "golden" "cantidad" => "5" ] 2 => array:1 [▼ "nombre" => "suprema" "cantidad" => "1" ] ]
i searched , found this didn't worked me...
since don't have strings keys can't use array_merge_recursive()
, loop through array , if key exists in other array , add array other array, e.g.
foreach($arr2 $k => $v){ if(isset($arr1[$k])) $arr1[$k] = $arr1[$k] + ["cantidad" => $v]; }
Comments
Post a Comment