Title, how to implement the set class of Java, in order to store the same object stored only once.
Reply content:
Title, how to implement the set class of Java, in order to store the same object stored only once.
There is no set function in PHP similar to java.
There are objects, arrays, and resources commonly used to store data in PHP.
Storing objects in PHP is usually implemented using arrays.
You just want to store the same object once, just to determine if the array already has the same object before you put the array, and the question turns into how to judge two objects the same .
When comparing two object variables using the contrast operator (= =), the principle of comparison is that if the properties and property values of the two objects are equal, and two objects are instances of the same class, the two object variables are equal.
If you use the strict equality operator (= = =), the two object variables must point to the same instance of a class (that is, the same object).
PHP does not have an existing set-type Object
In simple words, you can use the Array_unique function.
Use the PHP array, each time you insert, with the In_array () function to judge, does not exist insert