jason-数组去重

1. Array.from(new Set(arr)) //推荐
2. function unlink(arr) {
    return arr.filter(function (item, index, arr) {
        return arr.indexOf(item, 0) === index;
    });
}
$idSortData = ProductService::getIdSortProducts(); $adproducts = $idSortData['adproducts']; $pida = $idSortData['pida']; $section = $this['sortableDetailSection'](); $pida = array_unique(array_merge($pida, $section['pids'] ?? [])); $adproducts = array_values(array_column($adproducts, null, 'id') + array_column($section['items'] ?? [], null, 'id')); //sku置顶 if(!empty($pida)){ $primaryProduct = current($adproducts) ?: []; if(!empty($primaryProduct) && !empty(get('skuid')) && !empty(Products::getSkuOption($primaryProduct, get('skuid'))) ){ $this['primaryProduct'] = $primaryProduct; unset($adproducts[0]); unset($pida[0]); } } //勾选位置顶(批量产品置顶) $sortSectionCode = get('sort_code', ''); if(!empty($sortSectionCode)){ $sortSectionCodeArr = $sortSectionCode; if(is_string($sortSectionCode)){ $sortSectionCodeArr = explode(',', $sortSectionCode)??[]; } $sortSectionPids = []; foreach($sortSectionCodeArr as $code){ $sortSectionPids = array_merge($sortSectionPids, $this['catalog']->getSectionPids($code)); } $pida = array_values(array_unique(array_merge($pida, $sortSectionPids))); } $this['pida'] = $pida; $newSaleSection = $this['catalog']->ProductSection('best-sale'); $newSaleIds = $newSaleSection['section']['pids']??[]; $newSaleIds = collect(array_map('intval', $pida))->merge($newSaleIds)->unique()->values()->toArray(); $this['productsId'] = $newSaleIds; $products = App::make('Jason\Ccshop\Controllers\Products')->onLoadMoreProductsToEs($newSaleIds); $this['products'] = $products; $this['sortUrl'] = trim(str_replace('.html', '', $this->page->url),'/');
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值