阅读(655) (5)

Laravel 8 nth() {#collection-method}

2021-07-01 15:42:01 更新

nth 方法创建由每 n 个元素取一个元素组成的一个新集合:

$collection = collect(['a', 'b', 'c', 'd', 'e', 'f']);

$collection->nth(4);

// ['a', 'e']

你也可以设置指定的偏移位置作为第二个参数:

$collection->nth(4, 1);

// ['b', 'f']