Reputation: 16040
I need to exclude elements of the array $tempobjects
from the array $objects
. What is the quickest way to do this?
$objects = new MyObjects();
$tempobjects = new MyObjects();
for($i=0; $i<10; $i++) {
$objects->addObject(new MyObject(...));
}
//...fill $tempobjects with some temporary data
$tempobjects = $objects - $tempobjects; // HOW TO DO SOMETHING LIKE THIS?
Upvotes: 1
Views: 466
Reputation: 48212
If $tempobjects
and $objects
were arrays (like your title mentions), which based on your sample code they are not, you could exclude elements using functions array_diff() (for comparing values) or array_diff_key() (for comparing keys).
See, also, this short demo.
Upvotes: 2