【问题标题】:Intersection with redbeanphp与redbeanphp的交集
【发布时间】:2014-04-22 22:09:21
【问题描述】:

我有一个类型为 $contact 的 bean 的数组 $mycontacts

地点:

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

我想检查 $mycontacts 数组与第二个数组 $contacted 的类型也是 $contact。

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

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

有没有更好的方法来使用 php、redbean 或 mysql?

【问题讨论】:

    标签: php mysql redbean


    【解决方案1】:
    $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。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-12
      相关资源
      最近更新 更多