What can the For example, I have an array of objects and I want to add them explicitly to another array. Is it possible to check that an object has already been added: Or is there any other way? The function can not compare objects. You should make a unique key-value pair from your object and only compare those keys when inserting a new object into your final array. P> Assume that each object has a unique in_array function compare to objects?
in_array ($ different, $ object);
id property, possible solution will be:
$ unique_objects = array (); // $ data represents your object collection foreach ($ data as $ item) (if! (Array_key_exists ($ item-> ID, unique_object)) {$ unique_objects [$ idem- & gt; ID] = $ Obj;}}
No comments:
Post a Comment