Combine two different dimensional arrays PHP

后端 未结 4 1804
伪装坚强ぢ
伪装坚强ぢ 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:41

    Create new array and store it there. You can access the value of $array2 because they have the same index of $array1 so you can use the $key of these two arrays.

       $array3 = [];
       foreach($array1 as $key => $val) {
         $array3[] = [
           'id' => $val['id'],
           'price' => $val['price'],
           'purchase_time' => $val['purchase_time'],
           'Qty' => $array2[$key]
         ];
       }
    
      print_r($array3);
    

提交回复
热议问题