For example, how to implement the java set class is to store the same object only once. For example, how to implement the java set class is to store the same object only once.
Reply content:
For example, how to implement the java set class is to store the same object only once.
PHP does not have the set function similar to java.
Objects, arrays, and resources are commonly used to store data in PHP.
Objects stored in PHP are usually implemented using arrays.
You only want to store the same object once. You only need to judge whether the same object already exists in the array before placing it, so the problem is convertedHow to determine if two objects are the same.
When two object variables are compared using the comparison operator (=), the comparison principle is: if the attributes and attribute values of the two objects are equal, and the two objects are instances of the same class, the two object variables are equal.
If the full equality operator (=) is used, these two object variables must point to the same instance of a class (that is, the same object ).
PHP does not have a ready-made set object.
You can use the array_unique function in a simple way.
Use the php array, and use the in_array () function to determine each insert operation. If no input exists, insert the data.