I'm kind of new to programming and want to know if there is a short way to find the intersection of two arrays containing slightly different Objects. That's what I tried to use:
array_uintersect()
The Object are looking like this:
class object1
{
private $_customerId;
private $_orderId;
private $_someOtherStuff;
}
and:
class object2
{
private $_customerId;
private $_orderId;
private $_someDifferentStuff;
}
The custom function looking like this:
private function compareObjects($o1, $o2)
{
return $o1->compareObjectIntersection($o2);;
}
Using this method:
public function compareObjectIntersection($object)
{
if($this->_customerId < $object->getCustomerId() || $this->_orderId < $object->getOrderId())
{
return -1;
}
elseif$this->_customerId > $object->getCustomerId() || $this->_orderId > $object->getOrderId())
{
return 1;
}
return 0;
}
Is this possible without coding everything by myself with a lot of for-loops?
EDIT:
The idea was to get rid of all objects not containing the same pair of these two attributes:
private $_customerId;
private $_orderId;
In the first place i get an empty array as a result