首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Ds\Deque::slice

(PECL ds >= 1.0.0)

Ds \ Deque :: slice - 返回给定范围的子转角。

描述

代码语言:javascript
复制
public Ds\Deque Ds\Deque::slice ( int $index [, int $length ] )

创建给定范围的子队列。

参数

index

子队列开始的索引。

如果是肯定的,那么deque将从deque中的那个索引开始。如果消极,那么德克将从最后开始。

length

如果给出长度并且是正数,则所得到的deque将具有多达其中的许多值。如果长度导致溢出,则只包括直到双端队列结束的值。如果给定长度并且是负数,那么双端队列将从最后停止许多值。如果未提供长度,则所得到的双端队列将包含索引与双端队列之间的所有值。

返回值

给定范围的子队列。

例子

示例 #1 Ds\Deque::slice() example

代码语言:javascript
复制
<?php
$deque = new \Ds\Deque(["a", "b", "c", "d", "e"]);

// Slice from 2 onwards
print_r($deque->slice(2));

// Slice from 1, for a length of 3
print_r($deque->slice(1, 3));

// Slice from 1 onwards
print_r($deque->slice(1));

// Slice from 2 from the end onwards
print_r($deque->slice(-2));

// Slice from 1 to 1 from the end
print_r($deque->slice(1, -1));
?>

上面的例子会输出类似于:

代码语言:javascript
复制
Ds\Deque Object
(
    [0] => c
    [1] => d
    [2] => e
)
Ds\Deque Object
(
    [0] => b
    [1] => c
    [2] => d
)
Ds\Deque Object
(
    [0] => b
    [1] => c
    [2] => d
    [3] => e
)
Ds\Deque Object
(
    [0] => d
    [1] => e
)
Ds\Deque Object
(
    [0] => b
    [1] => c
    [2] => d
)

← Ds\Deque::shift

Ds\Deque::sort →

扫码关注腾讯云开发者

领取腾讯云代金券