When instantiating the object you can specify a second bool parameter, which will control the key searching in the object. 默认情况下$insensitive被设置为true，使得集合中的搜索不区分大小写。 Setting this value to false will make the search for the element in a case sensitive manner.
Using get() offers three extra parameters. When $defaultValue is defined in the call and the element is not found, $defaultValue will be returned. The cast parameter accepts a string that defines what the returned value will be casted. The available values are:
The collection object also offers two more getters getKeys and getValuesgetKeys( bool $insensitive = true ) returns all the keys stored internally in the collection. By default, it will return the keys case insensitive manner i.e. all lowercase. If false is passed in the call, it will return the keys exactly as they have been stored. getValues returns the values stored in the internal collection.
To check whether an element exists or not in the collection, you can use the following:
The \Serializable and \JsonSerializable interfaces expose methods that allow you to serialize and unserialize the object. serialize() and unserialize() use PHP’s serialize and unserialize functions. jsonSerialize() returns an array which can be used with json_encode to serialize the object.
Phalcon\Collection also exposes two transformation methods: toArray() and toJson(int $options). toArray() returns the object transformed as an array. This method returns the same array as jsonSerialize().
toJson(int $options) returns a JSON representation of the object. It uses json_encode internally and accepts a parameter, which represents the flags that json_encode accepts. By default the options are set up with the value 74, (RFC4327) which translates to:
You can pass any valid flags to the method according to your needs.
Phalcon also offers a component that can be used in a read-only fashion. Phalcon\Collection\ReadOnly can serve as a collection in your application that can only be populated with initial data but not allowing its contents to be changed throughout the application.