Combine two different dimensional arrays PHP

后端 未结 4 1807
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 05:18

I have two different dimensional arrays.

Array 1:

Array1 
(
[0] => Array
    (
        [id] => 123 
        [price] => 5
        [purchase_         


        
4条回答
  •  悲&欢浪女
    2021-01-20 05:36

    If the $array1 and $array2 are mapped by the same indexes, so they have same length, you can try:

    foreach($array2 as $index=>$quantity){
      $array1[$index]['Qty'] = $quantity;
    }
    

    And it´s done! If you want to keep the original $array1 untouched, you can make a copy before the foreach.

提交回复
热议问题