gpt4 book ai didi

php - 合并字段 laravel 集合

转载 作者:搜寻专家 更新时间:2023-10-31 21:51:17 25 4
gpt4 key购买 nike

我有两个 Laravel 集合。我的第一个集合名为 $custom_product:

Collection {#313 ▼
#items: array:1 [▼
0 => array:1 [▼
"custom_description" => "insert description here"
]
]
}

我还有另一个名为 $api_product 的集合:

Collection {#311 ▼
#items: array:29 [▼
"article_id" => 5570
"active" => null
"name" => "CORBATA POLIESTER"
"detail" => "- Pesa: 43 gr."
"constructor_name" => "gift"
"stock_available" => true
"stock" => null
"prices" => array:6 [▶]
"price_pvp" => 29.0
"size" => "1410X100"
]
}

我想要这个结果。相同的集合,但添加了字段 custom_description:

Collection {#311 ▼
#items: array:29 [▼
"article_id" => 5570
"active" => null
"custom_description" => "insert description here"//add this field
"name" => "CORBATA POLIESTER"
"detail" => "- Pesa: 43 gr."
"constructor_name" => "gift"
"stock_available" => true
"stock" => null
"prices" => array:6 [▶]
"price_pvp" => 29.0
"size" => "1410X100"
]
}

最佳答案

你可以使用 put 方法 laravel collection .

$collection = collect(['product_id' => 1, 'name' => 'Desk']);

$collection->put('price', 100);

$collection->all();

// ['product_id' => 1, 'name' => 'Desk', 'price' => 100]

关于php - 合并字段 laravel 集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41415324/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com