jeudi 9 février 2017

Merging Two Laravel Collections keeping the original keys

I have the following two collections:

Collection {#402 ▼
  #items: array:1 [▼
    4007 => "4007 - Container Deposit - 18.00 Drum - In Stock: 0.00"
  ]
}

Collection {#398 ▼
  #items: array:3 [▼
    1000 => "1000 - Acetone - 162.00 KG - In Stock: 10000.00"
    1001 => "1001 - Acetone - 15.80 KG - In Stock: 0.00"
    24662 => "24662 - 1L Untd Antifreeze Orange FO2272A60(Prem - 1.00 Litre - In Stock: 0.00"
  ]
}

Using Laravel's collection merge function:

$merged = $ref_prod_containers->merge($ref_cust_prod);
dd($merged);

I get the following:

Collection {#397 ▼
  #items: array:4 [▼
    0 => "4007 - Container Deposit - 18.00 Drum - In Stock: 0.00"
    1 => "1000 - Acetone - 162.00 KG - In Stock: 10000.00"
    2 => "1001 - Acetone - 15.80 KG - In Stock: 0.00"
    3 => "24662 - 1L Untd Antifreeze Orange FO2272A60(Prem - 1.00 Litre - In Stock: 0.00"
  ]
}

However I wish to retain the original keys. The merge function is removing them and replacing with 0,1,2,3.

Thanks, Julian



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k8Yxul
via IFTTT

Aucun commentaire:

Enregistrer un commentaire