Change language

PHP Ds / Sequence slice () function

Syntax:
DsSequence abstract public DsSequence::slice (int $index [, int $length])
Parameters:This function takes two parameters as above and described below:
  • $index:This parameter contains the starting index of the subsequence. The index value can be positive or negative. If the index value is positive, then it starts at the index of the sequence, and if the index value is negative, then the sequence starts at the end.
  • $length:This parameter contains the length of the subsequence. This parameter can take positive and negative values. If the length is positive, then the size of the subsequence is equal to the specified length, and if the length is negative, the sequence will stop that many values ​​from the end.
Return value:This function returns a subsequence of the specified range .The following programs illustrate the Ds / Sequence::slice()function in PHP:Program 1:  
// Create a new sequence $seq = new DsVector ([1, 3, 6, 9, 10, 15, 20]);  
// Use the slice() function to create
// subsequence and display it print_r ( $seq -> slice (2)); print_r ( $seq -> slice (1, 2)); print_r ( $seq -> slice (2, -2));  
?>
Output:
DsVector Object ([0] = > 6 [1] = > 9 [2] = > 10 [3] = > 15 [4] = > 20) DsVector Object ([0] = > 3 [1] = > 6) DsVector Object ([0] = > 6 [1] = > 9 [2] = > 10)
Program 2:  
// Create a new sequence $seq = new DsVector ([ "Geeks" , "GFG" , "Abc" , "for" ]);  
// Use the slice() function to create
// subsequence and display it print_r ( $seq -> slice (3)); print_r ( $seq -> slice (2, 0)); print_r ( $seq -> slice (0, 3));  
?>
Output:
DsVector Object ([0] = > for) DsVector Object() DsVector Object ([0] = > Geeks [1] = > GFG [2] = > Abc)
Link: http://php.net/manual/en/ds-sequence. slice.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method