PHP Class think\Collection

Inheritance: implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements IteratorAggregat\IteratorAggregate, implements JsonSerializabl\JsonSerializable
Show file Open project: top-think/framework Class Usage Examples

Protected Properties

Property Type Description
$items

Public Methods

Method Description
__construct ( $items = [] )
__toString ( )
all ( )
chunk ( integer $size, boolean $preserveKeys = false ) : static 把一个数组分割为新的数组块.
column ( $column_key, null $index_key = null ) : array 返回数组中指定的一列
count ( ) Countable
diff ( mixed $items ) : static 比较数组,返回差集
each ( callable $callback ) 给每个元素执行个回调
filter ( callable $callback = null ) : static 用回调函数过滤数组中的元素
flip ( ) : static 交换数组中的键和值
getIterator ( ) IteratorAggregate
intersect ( mixed $items ) : static 比较数组,返回交集
isEmpty ( ) : boolean 是否为空
jsonSerialize ( ) JsonSerializable
keys ( ) : static 返回数组中所有的键名
make ( $items = [] )
merge ( mixed $items ) : static 合并数组
offsetExists ( $offset ) ArrayAccess
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
pop ( ) : mixed 删除数组的最后一个元素(出栈)
reduce ( callable $callback, mixed $initial = null ) : mixed 通过使用用户自定义函数,以字符串返回数组
reverse ( ) : static 以相反的顺序返回数组。
shift ( ) : mixed 删除数组中首个元素,并返回被删除元素的值
shuffle ( ) : static 将数组打乱
slice ( integer $offset, integer $length = null, boolean $preserveKeys = false ) : static 截取数组
sort ( callable $callback = null ) : static 对数组排序
toArray ( )
toJson ( integer $options = JSON_UNESCAPED_UNICODE ) : string 转换当前数据集为JSON字符串
unshift ( mixed $value, null $key = null ) : integer 在数组开头插入一个元素

Protected Methods

Method Description
convertToArray ( mixed $items ) : array 转换成数组

Method Details

__construct() public method

public __construct ( $items = [] )

__toString() public method

public __toString ( )

all() public method

public all ( )

chunk() public method

把一个数组分割为新的数组块.
public chunk ( integer $size, boolean $preserveKeys = false ) : static
$size integer
$preserveKeys boolean
return static

column() public method

返回数组中指定的一列
public column ( $column_key, null $index_key = null ) : array
$column_key
$index_key null
return array

convertToArray() protected method

转换成数组
protected convertToArray ( mixed $items ) : array
$items mixed
return array

count() public method

Countable
public count ( )

diff() public method

比较数组,返回差集
public diff ( mixed $items ) : static
$items mixed
return static

each() public method

给每个元素执行个回调
public each ( callable $callback )
$callback callable

filter() public method

用回调函数过滤数组中的元素
public filter ( callable $callback = null ) : static
$callback callable
return static

flip() public method

交换数组中的键和值
public flip ( ) : static
return static

getIterator() public method

IteratorAggregate
public getIterator ( )

intersect() public method

比较数组,返回交集
public intersect ( mixed $items ) : static
$items mixed
return static

isEmpty() public method

是否为空
public isEmpty ( ) : boolean
return boolean

jsonSerialize() public method

JsonSerializable
public jsonSerialize ( )

keys() public method

返回数组中所有的键名
public keys ( ) : static
return static

make() public static method

public static make ( $items = [] )

merge() public method

合并数组
public merge ( mixed $items ) : static
$items mixed
return static

offsetExists() public method

ArrayAccess
public offsetExists ( $offset )

offsetGet() public method

public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

pop() public method

删除数组的最后一个元素(出栈)
public pop ( ) : mixed
return mixed

reduce() public method

通过使用用户自定义函数,以字符串返回数组
public reduce ( callable $callback, mixed $initial = null ) : mixed
$callback callable
$initial mixed
return mixed

reverse() public method

以相反的顺序返回数组。
public reverse ( ) : static
return static

shift() public method

删除数组中首个元素,并返回被删除元素的值
public shift ( ) : mixed
return mixed

shuffle() public method

将数组打乱
public shuffle ( ) : static
return static

slice() public method

截取数组
public slice ( integer $offset, integer $length = null, boolean $preserveKeys = false ) : static
$offset integer
$length integer
$preserveKeys boolean
return static

sort() public method

对数组排序
public sort ( callable $callback = null ) : static
$callback callable
return static

toArray() public method

public toArray ( )

toJson() public method

转换当前数据集为JSON字符串
public toJson ( integer $options = JSON_UNESCAPED_UNICODE ) : string
$options integer json参数
return string

unshift() public method

在数组开头插入一个元素
public unshift ( mixed $value, null $key = null ) : integer
$value mixed
$key null
return integer

Property Details

$items protected property

protected $items