PHP | Ds\Vector slice() Function Last Updated : 22 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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 hold the starting index of sub-vector. The index value can be positive and negative. If the index value is positive then it starts at the index of vector and if the index value is negative then it starts from ends. $length: This parameter holds the length of sub-vector. This parameter can take positive and negative values. If length is positive then sub-vector size is equal to a given length and if the length is negative then vector will stop that many values from the end. Return Value: This function returns a sub-vector of given range. Below programs illustrate the Ds\Vector::slice() function in PHP: Program 1: PHP <?php // Create new vector $vect = new \Ds\Vector([1, 2, 3, 4, 5, 6]); echo("Original vector:\n"); // Display the vector element var_dump($vect); // Use slice() function to // create sub vector $res = $vect->slice(1, 2); echo("\nNew sub-vector\n"); // Display the sub-vector elements var_dump($res); ?> Output: Original vector: object(Ds\Vector)#1 (6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) } New sub-vector object(Ds\Vector)#2 (2) { [0]=> int(2) [1]=> int(3) } Program 2: PHP <?php // Create new vector $vect = new \Ds\Vector([1, 2, 3, 4, 5, 6]); echo("Original vector:\n"); // Display the vector element var_dump($vect); // Use slice() function to // create sub vector $res = $vect->slice(2, -2); echo("\nNew sub-vector\n"); // Display the sub-vector elements var_dump($res); $res = $vect->slice(4); echo("\nNew sub-vector\n"); // Display the sub-vector elements var_dump($res); ?> Output: Original vector: object(Ds\Vector)#1 (6) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) } New sub-vector object(Ds\Vector)#2 (2) { [0]=> int(3) [1]=> int(4) } New sub-vector object(Ds\Vector)#3 (2) { [0]=> int(5) [1]=> int(6) } Reference: http://php.net/manual/en/ds-vector.slice.php Comment More infoAdvertise with us Next Article PHP | DsMap sort() Function B barykrg Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-ds_vector 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 | DsMap sort() Function The Ds\Map::sort() function of DS\Map class in PHP is used to in-place sort the elements of a specified Map instance according to the values. By default, the Map is sorted according to the increasing order of the values. Syntax: Ds\Pair public Ds\Map::sort ( int $position ) Parameter: This function 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 | 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 PHP | DsVector set() Function The Ds\Vector::set() function is an inbuilt function in PHP which is used to set the value in the vector at the given index. Syntax: void public Ds\Vector::set( $index, $value ) Parameters: This function accepts two parameters as mentioned above and described below: $index: This parameter holds the 2 min read PHP | DsMap remove() Function The Ds\Map::remove() function is an inbuilt function in PHP which is used to remove and return a value by key. Syntax: mixed Ds\Map::remove( $key, $default ) Parameters: This function accepts two parameters as mentioned above and described below: $key: It holds the key value which need to remove. $d 2 min read Like