PHP | Ds\Sequence slice() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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: $index: This parameter hold the starting index of subsequence. The index value can be positive and negative. If the index value is positive then it starts at the index of sequence and if the index value is negative then it sequence starts from ends. $length: This parameter holds the length of subsequence. This parameter can take positive and negative values. If length is positive then subsequence size is equal to a given length and if the length is negative then the sequence will stop that many values from the end. Return value: This function returns the subsequence of given range. Below programs illustrate the Ds\Sequence::slice() function in PHP: Program 1: php <?php // Create new sequence $seq = new \Ds\Vector([1, 3, 6, 9, 10, 15, 20]); // Use slice() function to create // sub sequence and display it print_r($seq->slice(2)); print_r($seq->slice(1, 2)); print_r($seq->slice(2, -2)); ?> Output: Ds\Vector Object ( [0] => 6 [1] => 9 [2] => 10 [3] => 15 [4] => 20 ) Ds\Vector Object ( [0] => 3 [1] => 6 ) Ds\Vector Object ( [0] => 6 [1] => 9 [2] => 10 ) Program 2: php <?php // Create new sequence $seq = new \Ds\Vector(["Geeks", "GFG", "Abc", "for"]); // Use slice() function to create // sub sequence and display it print_r($seq->slice(3)); print_r($seq->slice(2, 0)); print_r($seq->slice(0, 3)); ?> Output: Ds\Vector Object ( [0] => for ) Ds\Vector Object ( ) Ds\Vector Object ( [0] => Geeks [1] => GFG [2] => Abc ) Reference: http://php.net/manual/en/ds-sequence.slice.php Comment More infoAdvertise with us Next Article PHP | DsMap reverse() Function V vijay_raj Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-DS\Collection 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 | DsMap reverse() Function The Ds/Map::reverse() function in PHP is used to in-place reverse the elements of a specified Map instance. That is, the function in-place reverses the order of elements present in the specified Map instance. Syntax: Ds\Map public Ds\Map::reverse ( int $position ) Parameter: This function does not a 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 | DsMap values() Function The Ds\Map::values() function is an inbuilt function in PHP which is used to return a sequence of the map's values. Syntax: Ds\Sequence public Ds\Map::values ( void ) Parameters: This function does not accepts any parameters. Return Value: It returns a Ds\Sequence containing all the values of the ma 1 min read PHP | DsDeque unshift() Function The Ds\Deque::unshift() function is an inbuilt function in PHP which is used to add the value in front of the deque. Syntax: void Ds\Deque::unshift( $values ) Parameters: This function accepts single parameter $values which holds the values to add in the front of the deque. Return Value: This functi 2 min read PHP array_splice() Function This inbuilt function of PHP is an advanced and extended version of array_slice() function, where we not only can remove elements from an array but can also add other elements to the array. The function generally replaces the existing element with elements from other arrays and returns an array of r 2 min read PHP | DsDeque reverse() Function The Ds\Deque::reverse() function is an inbuilt function in PHP which is used to reverse the elements in the Deque in-place. Syntax: public Ds\Deque::reverse( void ) : void Parameters: This function does not accept any parameter. Return Value: This function does not return any value. Below programs i 2 min read Like