[PHP]
if (is_array($_POS T["assoc_$key "])) {
foreach ($this->getAssocSectio nsObjArray($key , $dbAP) as
$obj) {
print_r($obj); print_r(" in array? ");
print_r(in_arra y($obj, $result)); print_r("<P>");
if (!in_array($obj , $result)) array_push($res ult, $obj);
}
}
[/PHP]
Here is the output of the result of this script:
What I have to do is compare an array of objects, $result, with
another array of objects, $this->getAssocSectio nsObjArray($key ,
$dbAP). Both arrays will be identical in structure and object
formatting, but not in object data content. What I need to do is to
find out if that one array has the very same object as the other, then
don't add it to $result, otherwise, add to $result.
The object formatting is as follows:
And $result can look like this:
I don't wish to loop through both arrays, that would be a performance
nightmare to do that. Is there a version of in_array in existence for
comparing objects?
Thanx
Phil
PS: I went to this manual example at
but that involves recursive handling and object rebuilding - this,
were I to figure out what the living blue it is, would have to be put
inside another loop.. OUCH!
if (is_array($_POS T["assoc_$key "])) {
foreach ($this->getAssocSectio nsObjArray($key , $dbAP) as
$obj) {
print_r($obj); print_r(" in array? ");
print_r(in_arra y($obj, $result)); print_r("<P>");
if (!in_array($obj , $result)) array_push($res ult, $obj);
}
}
[/PHP]
Here is the output of the result of this script:
stdClass Object ( [id] => 2 [placement_name] => Placement #1 ) in
array?
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 99
Warning: in_array(): Wrong datatype for first argument in
/www/html/mu-spin/image_catalog/include/classes.inc.php on line 100
stdClass Object ( [id] => 4 [placement_name] => Placement #10 ) in
array?
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 99
Warning: in_array(): Wrong datatype for first argument in
/www/html/mu-spin/image_catalog/include/classes.inc.php on line 100
stdClass Object ( [id] => 6 [placement_name] =>
http://blah.com ) in array?
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 99
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 100
array?
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 99
Warning: in_array(): Wrong datatype for first argument in
/www/html/mu-spin/image_catalog/include/classes.inc.php on line 100
stdClass Object ( [id] => 4 [placement_name] => Placement #10 ) in
array?
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 99
Warning: in_array(): Wrong datatype for first argument in
/www/html/mu-spin/image_catalog/include/classes.inc.php on line 100
stdClass Object ( [id] => 6 [placement_name] =>
http://blah.com ) in array?
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 99
Warning: in_array(): Wrong datatype for first argument in
/image_catalog/include/classes.inc.php on line 100
another array of objects, $this->getAssocSectio nsObjArray($key ,
$dbAP). Both arrays will be identical in structure and object
formatting, but not in object data content. What I need to do is to
find out if that one array has the very same object as the other, then
don't add it to $result, otherwise, add to $result.
The object formatting is as follows:
obj: stdClass Object ( [id] => 2 [placement_name] => Placement
#1 )
#1 )
result: Array ( [0] => stdClass Object ( [id] => 6 [placement_name] =>
Placement #27 ) [1] => stdClass Object ( [id] => 2 [placement_name] =>
Placement #1 ) )
Placement #27 ) [1] => stdClass Object ( [id] => 2 [placement_name] =>
Placement #1 ) )
nightmare to do that. Is there a version of in_array in existence for
comparing objects?
Thanx
Phil
PS: I went to this manual example at
but that involves recursive handling and object rebuilding - this,
were I to figure out what the living blue it is, would have to be put
inside another loop.. OUCH!
Comment