I have an array $mycontacts of beans of type $contact
where:
$contact->id = $x
$contact->name = $y
$contact->email= $z
I want to check the $mycontacts array against a second array $contacted also of type $contact.
I want to perform $mycontacts - $contacted to yield a subset which I have not contacted based on the email parameter. Now i could do something like
foreach ($mycontacts as $mycontact) {
loop through $contacted and compare $contacted->email to $mycontact->email
}
Is there a better way to do this either with php, redbean or 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 );
This code should be the best performing, as it runs nearly entirely on the database, which is the best place to work with sets of data. It first selects all contacts, then subtracts "my contacts" and returns the result. RedBean then converts it back to beans.