0

I have an array of objects. Each object in the array has the property recipeID. I'm looking to delete an object if its recipeID property matches another object's recipeID property.
Basically, I would like to perform a array_unique() on the array of objects but using the $object->recipeID as criterion that is being checked against.

For example, why wouldn't this work?

array_unique($objectArray);

If the recipeID property in two objects were the same, wouldn't that make those two objects equal? Assuming there were no other properties. Then array_unique() would see a multiple and delete one of them.

fuesika
  • 3,280
  • 6
  • 26
  • 34
wimbletim
  • 103
  • 1
  • 10
  • Please add some code as a minimum (non)working example. – fuesika Apr 07 '15 at 03:22
  • To directly answer your question, from [the manual](http://php.net/manual/function.array-unique.php) ~ *"**Note:** Two elements are considered equal if and only if (string) $elem1 === (string) $elem2 i.e. when the string representation is the same, the first element will be used."* – Phil Apr 07 '15 at 03:56
  • @pyStarter That exactly what I was looking for....I didn't find that when I searched. Thank you! – wimbletim Apr 07 '15 at 04:05

0 Answers0