PHP - DS Collection Functions



The conventional array data structure is replaced by an OOP concept called a Collection class. A collection has member elements, like an array, although these are usually similar to objects rather than most basic types like texts and numbers.

An array of objects can be wrapped by the Collection classes. The collections can have new elements added, as well as existing elements changed or removed.

Basically, these collection classes have features that are shared by all the data structures in the library. It ensures that all structures can be counted, traversed, and encoded into JSON using json_encode(). There are four collection functions in PHP.

List of Functions

Following are various functions provided by the Collection class −

Sr.No Function & Description
1

Ds\Collection::clear()

Ds\Collection::clear() function can remove all values.

2

Ds\Collection::copy()

Ds\Collection::copy() function can return a shallow copy of the collection.

3

Ds\Collection::isEmpty()

Ds\Collection::isEmpty() function can return whether the collection is empty.

4

Ds\Collection::toArray()

Ds\Collection::toArray() function can convert the collection to an array.

php_function_reference.htm
Advertisements