【发布时间】:2018-01-20 17:29:30
【问题描述】:
我得到了以下收藏:
$this->items = collect([$productId => [
'name' => $product->title,
'price' => $product->price,
'is_sale' => $product->is_sale,
'sale_price' => $product->sale_price,
'sale_percent' => $product->sale_percent,
'can_use_promocode' => $product->can_use_promocode,
'qty' => 1,
]);
]);
如何使用键搜索项目?在文档中 (https://laravel.com/docs/5.2/collections) 我没有看到任何方法
UPD:例如,用户将商品添加到购物车 ($this->items)。我想检查购物车中是否存在物品(需要用钥匙来做)。用于 php 函数 array_key_exists 的模拟,但用于集合。
【问题讨论】:
-
你想在这里搜索什么??
-
@Sohel0415 检查问题,更新:)
-
你要搜索它,用哪一个键?