I have this array
Array
(
[0] => posts Object
(
[title] => test1
[dbh] => DataBase Object
(
[dbh] => PDO Object ( )
)
)
[1] => posts Object
(
[title] => test1
[dbh] => DataBase Object
(
[dbh] => PDO Object ( )
)
)
[2] => posts Object
(
[title] => test2
[dbh] => DataBase Object
(
[dbh] => PDO Object ( )
)
)
)
I can’t use array_unique(), because the the object can’t to be converted to string
The best way would be to not use foreach. You should use for:
Foreach makes a copy of your array and loops over the copy, which makes it a bit more complicated to keep track of which duplicates is already tested/removed.
The code above will check if your
postObjects are of the same instance, and remove if they are. You might want to check if they contain the same data, but are not of the same instance. Then you will have to expand theifline a little bit:…for checking if title is the same and the
DataBaseobjects are of the same instance.