Properties

$items

$items : array

Type

array — 数据

Methods

__construct()

__construct(array  $items = array()) 

Collection constructor.

Parameters

array $items

数据

make()

make(array  $items = array()) : static

创建 Collection 实例

Parameters

array $items

数据

Returns

static

isEmpty()

isEmpty() : boolean

判断数据是否为空

Returns

boolean

toArray()

toArray() : array

将数据转成数组

Returns

array

all()

all() : array

获取全部的数据

Returns

array

flip()

flip() : static

交换数组中的键和值

Returns

static

keys()

keys() : static

返回数组中所有的键名组成的新 Collection 实例

Returns

static

merge()

merge(mixed  $items) : static

合并数组并返回一个新的 Collection 实例

Parameters

mixed $items

新的数据

Returns

static

diff()

diff(mixed  $items) : static

比较数组,返回差集生成的新 Collection 实例

Parameters

mixed $items

做比较的数据

Returns

static

intersect()

intersect(mixed  $items) : static

比较数组,返回交集组成的 Collection 新实例

Parameters

mixed $items

比较数据

Returns

static

pop()

pop() : mixed

返回并删除数据中的的最后一个元素(出栈)

Returns

mixed

shift()

shift() : mixed

返回并删除数据中首个元素

Returns

mixed

unshift()

unshift(mixed  $value, mixed  $key = null) : void

在数组开头插入一个元素

Parameters

mixed $value

mixed $key

键名

push()

push(mixed  $value, mixed  $key = null) : void

在数组结尾插入一个元素

Parameters

mixed $value

mixed $key

键名

reduce()

reduce(callable  $callback, mixed  $initial = null) : mixed

通过使用用户自定义函数,以字符串返回数组

Parameters

callable $callback

回调函数

mixed $initial

初始值

Returns

mixed

reverse()

reverse() : static

以相反的顺序创建一个新的 Collection 实例

Returns

static

chunk()

chunk(integer  $size, boolean  $preserveKeys = false) : static

把数据分割为新的数组块

Parameters

integer $size

分隔长度

boolean $preserveKeys

是否保持原数据索引

Returns

static

each()

each(callable  $callback) : $this

给数据中的每个元素执行回调

Parameters

callable $callback

回调函数

Returns

$this

filter()

filter(callable|null  $callback = null) : static

用回调函数过滤数据中的元素

Parameters

callable|null $callback

回调函数

Returns

static

column()

column(mixed  $columnKey, null  $indexKey = null) : array

返回数据中指定的一列

Parameters

mixed $columnKey

键名

null $indexKey

作为索引值的列

Returns

array

sort()

sort(callable|null  $callback = null) : static

对数据排序,并返回排序后的数据组成的新 Collection 实例

Parameters

callable|null $callback

回调函数

Returns

static

shuffle()

shuffle() : static

将数据打乱后组成新的 Collection 实例

Returns

static

slice()

slice(integer  $offset, integer  $length = null, boolean  $preserveKeys = false) : static

截取数据并返回新的 Collection 实例

Parameters

integer $offset

起始位置

integer $length

截取长度

boolean $preserveKeys

是否保持原先的键名

Returns

static

offsetExists()

offsetExists(mixed  $offset) : boolean

指定的键是否存在

Parameters

mixed $offset

键名

Returns

boolean

offsetGet()

offsetGet(mixed  $offset) : mixed

获取指定键对应的值

Parameters

mixed $offset

键名

Returns

mixed

offsetSet()

offsetSet(mixed  $offset, mixed  $value) : void

设置键值

Parameters

mixed $offset

键名

mixed $value

offsetUnset()

offsetUnset(mixed  $offset) : void

删除指定键值

Parameters

mixed $offset

键名

count()

count() : integer

统计数据的个数

Returns

integer

getIterator()

getIterator() : \ArrayIterator

获取数据的迭代器

Returns

\ArrayIterator

jsonSerialize()

jsonSerialize() : array

将数据反序列化成数组

Returns

array

toJson()

toJson(integer  $options = JSON_UNESCAPED_UNICODE) : string

转换当前数据集为 JSON 字符串

Parameters

integer $options

json 参数

Returns

string

__toString()

__toString() : string

将数据转换成字符串

Returns

string

load()

load(mixed  $relation) : $this

延迟预载入关联查询

Parameters

mixed $relation

关联

Returns

$this

hidden()

hidden(array  $hidden = array(), boolean  $override = false) : $this

设置需要隐藏的输出属性

Parameters

array $hidden

属性列表

boolean $override

是否覆盖

Returns

$this

visible()

visible(array  $visible = array(), boolean  $override = false) : $this

设置需要输出的属性

Parameters

array $visible
boolean $override

是否覆盖

Returns

$this

append()

append(array  $append = array(), boolean  $override = false) : $this

设置需要追加的输出属性

Parameters

array $append

属性列表

boolean $override

是否覆盖

Returns

$this

convertToArray()

convertToArray(mixed  $items) : array

将数据转换成数组

Parameters

mixed $items

数据

Returns

array