tags:

views:

60

answers:

4

I'm new to PHP, and I can't figure out this basic question. Does PHP have some sort of set or list object? Something like an array, but with the ability to dynamically add or remove any number of objects from it.

+3  A: 

Yes, you could use the array object and the array functions.

Basically, you could dynamically grow an array using the array_push function, or the $arrayName[] = ... notation (where arrayName is the name of your array).

Miky Dinescu
+1  A: 

PHP's arrays like a mashup of ordered arrays indexed by a number, and a hash lookup table. You can look up any element by a string index, but elements also have a defined order.

Andy Lester
+2  A: 

Just use a php array, there's no such thing as a 'fixed size' array in PHP so you should be fine with them.

Andrew Dunn
+1  A: 

Since you've mentioned a "Set object" in the question's title (i.e. if you need the objects not to be repeated within the set) , take a look at SplObjectStorage (php 5.3+).

VolkerK