How do I write code such that I can put things in a set and only the unique entries are kept?
for($i=0;$i<$count;$i++) {
$variable->put($some_object)
}
How do I write code such that I can put things in a set and only the unique entries are kept?
for($i=0;$i<$count;$i++) {
$variable->put($some_object)
}
$s = new SplObjectStorage();
$s->attach($some_object);
$s->attach($some_other_object);
Note that you can also use arrays, the keys are unique and reassigning a new value to existing key overwrites the new one. But with arrays you have come up with your own ID-s, with SplObjectStorage you don't.
Array example
$a = array();
$a['key1'] = $some_object;
$a['key1'] = $some_other_object;
In the above example only 'key1' is kept.