I am relatively new to php and have difficulty understanding the correct data structure. Say I have a FooBar class with equals()and hashCode()that has been correctly implemented. What is the collection in php (if any) that looks most like Java hashSet? I need a collection of objects without duplicates. Someone suggested using an array and a function array_key_exists, but I'm just wondering if there is another way to do this?
equals()
hashCode()
array_key_exists
Starting with version 5.2, Php offers SplObjectStorage, which offers the functionality of the Java Set:
http://technosophos.com/content/set-objects-php-arrays-vs-splobjectstorage, ,
PHP , PHP (SPL). Java Collections Framework, , , . .
, HashSet, PHP SplObjectStorage.
:
SplObjectStorage , , . .
PHP equals() hashCode(). , spl_object_hash(). SplObjectStorage , . SplObjectStorage::getHash($object) , SplObjectStorage.
spl_object_hash()
SplObjectStorage
SplObjectStorage::getHash($object)