Equivalent to Java HashSet in PHP

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?

+5
source share
2 answers

Starting with version 5.2, Php offers SplObjectStorage, which offers the functionality of the Java Set:

  • It takes care of uniqueness (the same object cannot be added twice)
  • Simple collection iteration

http://technosophos.com/content/set-objects-php-arrays-vs-splobjectstorage, ,

+3

PHP , PHP (SPL). Java Collections Framework, , , . .

, HashSet, PHP SplObjectStorage.

:

SplObjectStorage , , . .

PHP equals() hashCode(). , spl_object_hash(). SplObjectStorage , . SplObjectStorage::getHash($object) , SplObjectStorage.

+2

All Articles