The Ds\Set::slice()
function in PHP is used to return the subset of a given range.
The slice()
function can be declared as shown in the code snippet below:
Ds\Set public Ds\Set::slice ( int $ind [, int $len ] )
ind
: This is the starting index of the subset.Note: If
ind
is negative, then indexing of the set is started from the end of the set to its start.
len
: This is the length of the subset.The slice()
function returns the subset of a given range.
The code snippet below demonstrates the use of the slice()
function:
<?php$s1 = new \Ds\Set([5, 10, 15, 20, 25, 30]);print_r($s1->slice(2, 4));print_r($s1->slice(3));?>
s1
.slice()
function to get a subset of s1
from index 0
of length 3
.slice()
function to get a subset of s1
from index 3
until the end of the set s1
.