让我解释一下我的情况,我得到了一个多维数组。下面是print_r我的数组。 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 ))如您所见,有一个重复的数组,只有order_count不同的。我可以使用 轻松删除重复项array_unique,但随后它会随机删除其中一个数组(我相信)。我想要的是基于电子邮件(private_information)以最少的order_count. (所以只保留最高的那个order_count)任何人都可以在这里帮助我吗?
1 回答
Smart猫小萌
TA贡献1911条经验 获得超7个赞
基于提供的数组的解决方案是:
$filtered = [];
foreach ($array as $item) {
$email = $item['email'];
if (empty($filtered[$email]) || $filtered[$email]['order_count'] < $item['order_count']) {
$filtered[$email] = $item;
}
}
- 1 回答
- 0 关注
- 68 浏览
添加回答
举报
0/150
提交
取消