gpt4 book ai didi

php - 与 redbeanphp 的交集

转载 作者:行者123 更新时间:2023-11-29 08:03:17 24 4
gpt4 key购买 nike

我有一个$mycontacts 数组,其中包含$contact 类型的bean

地点:

$contact->id = $x
$contact->name = $y
$contact->email= $z

我想根据第二个同样为 $contact 类型的数组 $contacted 检查 $mycontacts 数组。

我想执行 $mycontacts - $contacted 以根据电子邮件参数生成我未联系过的子集。现在我可以做类似的事情

foreach ($mycontacts as $mycontact) {
loop through $contacted and compare $contacted->email to $mycontact->email
}

有没有更好的方法可以使用 php、redbean 或 mysql 来做到这一点?

最佳答案

$sql = 'SELECT * 
FROM contact
WHERE id NOT IN (SELECT mycontact.id
FROM contact AS mycontact
WHERE 1/* your condition*/)';
$rows = R::getAll( $sql );
$contactsMinusMyContacts = R::convertToBeans( 'contact', $rows );

此代码应该是性能最佳的,因为它几乎完全在数据库上运行,而数据库是处理数据集的最佳位置。它首先选择所有联系人,然后减去“我的联系人”并返回结果。然后 RedBean 将其转换回 Bean。

关于php - 与 redbeanphp 的交集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23231135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com