第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

PHP刪除重復(fù)的數(shù)組值

PHP刪除重復(fù)的數(shù)組值

PHP
月關(guān)寶盒 2022-06-17 10:11:45
讓我解釋一下我的情況,我得到了一個(gè)多維數(shù)組。下面是print_r我的數(shù)組。    Array(    [0] => Array        (            [firstname] => Tinga            [lastname] =>             [email] => private@information.nl            [country_code] => NL            [group] => B2B            [order_count] => 321        )    [1] => Array        (            [firstname] => Tinga            [lastname] =>             [email] => private@information.nl            [country_code] => NL            [group] => B2B            [order_count] => 12        )    [2] => Array        (            [firstname] => Rijsbergen Automotive B.V.            [lastname] =>             [email] => private@information1.nl            [country_code] => NL            [group] => B2B            [order_count] => 311        )    [3] => Array        (            [firstname] => Mike Verhoef            [lastname] => Artis Garage Amsterdam            [email] => private@information2.nl            [country_code] => NL            [group] => B2B            [order_count] => 260        )    [4] => Array        (            [firstname] => Marc Kraak            [lastname] => Vakgarage TEMA            [email] => private@information3.nl            [country_code] => NL            [group] => B2B            [order_count] => 257        )    [5] => Array        (            [firstname] => J&B Auto's            [lastname] =>             [email] => private@information4.nl            [country_code] => NL            [group] => B2B            [order_count] => 249        ))如您所見(jiàn),有一個(gè)重復(fù)的數(shù)組,只有order_count不同的。我可以使用 輕松刪除重復(fù)項(xiàng)array_unique,但隨后它會(huì)隨機(jī)刪除其中一個(gè)數(shù)組(我相信)。我想要的是基于電子郵件(private_information)以最少的order_count. (所以只保留最高的那個(gè)order_count)任何人都可以在這里幫助我嗎?
查看完整描述

1 回答

?
Smart貓小萌

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊

基于提供的數(shù)組的解決方案是:


$filtered = [];

foreach ($array as $item) {

    $email = $item['email'];


    if (empty($filtered[$email]) || $filtered[$email]['order_count'] < $item['order_count']) {

        $filtered[$email] = $item;

    }

}


查看完整回答
反對(duì) 回復(fù) 2022-06-17
  • 1 回答
  • 0 關(guān)注
  • 100 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)