PHP | Ds\Set slice() Function Last Updated : 16 Aug, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The Ds\Set::slice() function is an inbuilt function in PHP which is used to return the sub-set of given range. Syntax: Ds\Set public Ds\Set::slice ( int $index [, int $length ] ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the starting index of sub-set. The index value can be positive and negative. If the index value is positive then it starts at the index of the set and if the index value is negative then set starts from ends. $length: This parameter holds the length of sub-set. This parameter can take positive and negative values. If length is positive then sub-set size is equal to a given length and if the length is negative then the set will stop that many values from the end. Return Value: This function returns the sub-set of given range. Below programs illustrate the Ds\Set::slice() function in PHP: Program 1: php <?php // Create new set $set = new \Ds\Set([1, 3, 6, 9, 10, 15, 20]); // Use slice() function to create // sub-set and display it print_r($set->slice(2)); print_r($set->slice(1, 2)); print_r($set->slice(2, -2)); ?> Output: Ds\Set Object ( [0] => 6 [1] => 9 [2] => 10 [3] => 15 [4] => 20 ) Ds\Set Object ( [0] => 3 [1] => 6 ) Ds\Set Object ( [0] => 6 [1] => 9 [2] => 10 ) Program 2: php <?php // Create new set $set = new \Ds\Set(["Geeks", "GFG", "Abc", "for"]); // Use slice() function to create // sub-set and display it print_r($set->slice(3)); print_r($set->slice(2, 0)); print_r($set->slice(0, 3)); ?> Output: Ds\Set Object ( [0] => for ) Ds\Set Object ( ) Ds\Set Object ( [0] => Geeks [1] => GFG [2] => Abc ) Reference: https://www.php.net/manual/en/ds-set.slice.php Comment More infoAdvertise with us Next Article PHP | DsDeque slice() Function R R_Raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_set Similar Reads PHP | DsSet slice() Function The Ds\Set::slice() function is an inbuilt function in PHP which is used to return the sub-set of given range. Syntax: Ds\Set public Ds\Set::slice ( int $index [, int $length ] ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP | DsDeque slice() Function The Ds\Deque::slice() function is an inbuilt function in PHP which is used to return a sub-Deque which contains elements of the Deque within the index range. Syntax: public Ds\Deque::slice( $index, $length ) : Ds\Deque Parameters: This function accept two parameters as mentioned above and described 2 min read PHP | DsVector slice() Function The Ds\Vector::slice() function is an inbuilt function in PHP which is used to return the sub-vector of the given vector. Syntax: Ds\Vector public Ds\Vector::slice( $index, $length )/pre> Parameters: This function accepts two parameter as mentioned above and described below: $index: This parameter h 2 min read PHP | DsSequence slice() Function The Ds\Sequence::slice() function is an inbuilt function in PHP which is used to return the subsequence of given range. Syntax: Ds\Sequence abstract public Ds\Sequence::slice ( int $index [, int $length ] ) Parameters: This function accepts two parameters as mentioned above and described below: $ind 2 min read PHP array_slice() Function The array_slice() is an inbuilt function of PHP and is used to fetch a part of an array by slicing through it, according to the users choice.Syntax: array_slice($array, $start_point, $slicing_range, preserve) Parameters: This function can take four parameters and are described below: $array (mandato 3 min read PHP | DsDeque set() Function The Ds\Deque::set() function is an inbuilt function in PHP which is used to set the value at the given index in the Deque. Syntax: public Ds\Deque::set( $index, $value ) : void Parameters: This function accept two parameters as mentioned above and described below: index: This parameter holds the ind 2 min read Like