【发布时间】:2017-12-25 19:16:25
【问题描述】:
我有一个包含前 5 个产品的排序数组
foreach ($bestsellers as $item) {
$data = json_decode($item->order_details, true);
$product_ids[] = key($data);
}
arsort($product_ids);
$three = array_unique(array_slice($product_ids, 0, 5, true));
print_r($three);
结果是
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
1,2,3,4,5 是产品 ID。是否可以在查询产品表中使用此值,以便我可以在页面上显示有关产品的更多信息。不仅仅是 ID。
有点像
Product::where('product_id', $value);
更新
$best = Product::whereIn('product_id', $three)->get();
foreach($best as $info)
{
dd($info->title);
}
【问题讨论】: