Set
class Set extends AbstractSet (View source)
A set is a collection that contains no duplicate elements.
Great care must be exercised if mutable objects are used as set elements. The behavior of a set is not specified if the value of an object is changed in a manner that affects equals comparisons while the object is an element in the set.
Example usage:
$foo = new \My\Foo();
$set = new Set(\My\Foo::class);
$set->add($foo); // returns TRUE, the element don't exists
$set->add($foo); // returns FALSE, the element already exists
$bar = new \My\Foo();
$set->add($bar); // returns TRUE, $bar !== $foo
Traits
Properties
protected array | $data | The items of this array. | from AbstractArray |
Methods
Constructs a set object of the specified type, optionally with the specified data.
Returns true
if the given offset exists in this array.
Sets the given value to the given offset in this set, if it is not already present.
Removes the given offset and its value from the array.
Returns a serialized string representation of this array object.
Converts a serialized string representation into an instance object.
Returns true
if value is of the specified type.
Returns a string representation of the value.
Extracts the value of the given property or method from the object.
Adds the specified element to this set, if it is not already present.
Returns true
if this collection contains the specified element.
Removes a single instance of the specified element from this collection, if it is present.
Returns the values from given property or method.
Returns a sorted collection.
Returns a filtered collection.
Returns a collection of matching items.
Applies a callback to each item of the collection.
Create a new collection with divergent items between current and given collection.
Create a new collection with intersecting item between current and given collection.
Merge current items and items of given collections into a new one.
Returns the type associated with this set.
Details
at line 56
__construct(string $setType, array $data = [])
Constructs a set object of the specified type, optionally with the specified data.
in AbstractArray at line 51
Traversable
getIterator()
Returns an iterator for this array.
in AbstractArray at line 65
bool
offsetExists(mixed $offset)
Returns true
if the given offset exists in this array.
in AbstractArray at line 80
mixed|null
offsetGet(mixed $offset)
Returns the value at the specified offset.
in AbstractSet at line 56
void
offsetSet(mixed|null $offset, mixed $value)
Sets the given value to the given offset in this set, if it is not already present.
in AbstractArray at line 110
void
offsetUnset(mixed $offset)
Removes the given offset and its value from the array.
in AbstractArray at line 122
string
serialize()
Returns a serialized string representation of this array object.
in AbstractCollection at line 336
void
unserialize(string $serialized)
Converts a serialized string representation into an instance object.
in AbstractArray at line 146
int
count()
Returns the number of items in this array.
in AbstractArray at line 154
void
clear()
Removes all items from this array.
in AbstractArray at line 164
array
toArray()
Returns a native PHP array representation of this array object.
in AbstractArray at line 174
bool
isEmpty()
Returns true
if this array is empty.
protected bool
checkType(string $type, mixed $value)
Returns true
if value is of the specified type.
in ValueToStringTrait at line 38
protected string
toolValueToString(mixed $value)
Returns a string representation of the value.
- null value:
'NULL'
- boolean:
'TRUE'
,'FALSE'
- array:
'Array'
- scalar: converted-value
- resource:
'(type resource #number)'
- object with
__toString()
: result of__toString()
- object DateTime: ISO 8601 date
- object:
'(className Object)'
- anonymous function: same as object
in ValueExtractorTrait at line 35
protected mixed
extractValue(object $object, string $propertyOrMethod)
Extracts the value of the given property or method from the object.
in AbstractSet at line 37
bool
add(mixed $element)
Adds the specified element to this set, if it is not already present.
in AbstractCollection at line 61
bool
contains(mixed $element, bool $strict = true)
Returns true
if this collection contains the specified element.
in AbstractCollection at line 95
bool
remove(mixed $element)
Removes a single instance of the specified element from this collection, if it is present.
in AbstractCollection at line 115
array
column(string $propertyOrMethod)
Returns the values from given property or method.
in AbstractCollection at line 133
mixed
first()
Returns the first item of the collection.
in AbstractCollection at line 151
mixed
last()
Returns the last item of the collection.
in AbstractCollection at line 178
CollectionInterface
sort(string $propertyOrMethod, string $order = self::SORT_ASC)
Returns a sorted collection.
{@inheritdoc}
in AbstractCollection at line 205
CollectionInterface
filter(callable $callback)
Returns a filtered collection.
{@inheritdoc}
in AbstractCollection at line 225
CollectionInterface
where(string $propertyOrMethod, mixed $value)
Returns a collection of matching items.
{@inheritdoc}
in AbstractCollection at line 244
CollectionInterface
map(callable $callback)
Applies a callback to each item of the collection.
{@inheritdoc}
in AbstractCollection at line 264
CollectionInterface
diff(CollectionInterface $other)
Create a new collection with divergent items between current and given collection.
in AbstractCollection at line 292
CollectionInterface
intersect(CollectionInterface $other)
Create a new collection with intersecting item between current and given collection.
in AbstractCollection at line 314
CollectionInterface
merge(CollectionInterface ...$collections)
Merge current items and items of given collections into a new one.
at line 67
string
getType()
Returns the type associated with this set.