Change language

PHP Ds / Set slice () function

Syntax:
DsSet public DsSet::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 subset. The index value can be positive or negative. If the index value is positive, then it starts at the index of the set, and if the index value is negative, then the set starts at the end.
  • $length:This parameter contains the length of the subset. This parameter can take positive and negative values. If the length is positive, then the size of the subset is equal to the given length, and if the length is negative, then the set will stop so many values ​​from the end.
Return value:This function returns a subset of the given range.The following programs illustrate the Ds / Set::slice()function in PHP:Program 1:  
// Create a new set $set = new DsSet ([1, 3, 6, 9, 10, 15, 20]);  
// Use the slice() function to create
// subset and display it print_r ( $set -> slice (2)); print_r ( $set -> slice (1, 2)); print_r ( $set -> slice (2, -2));  
?>
Exit:
DsSet Object ( [0] = > 6 [1] = > 9 [2] = > 10 [3] = > 15 [4] = > 20) DsSet Object ([0] = > 3 [1] = > 6) DsSet Object ([0] = > 6 [1] = > 9 [2] = > 10)
Program 2:  
// Create a new set $set = new DsSet ([ "Geeks" , "GFG" , "Abc" , "for" ]);  
// Use the slice() function to create
// subset and display it print_r ( $set -> slice (3)); print_r ( $set -> slice (2, 0)); print_r ( $set -> slice (0, 3));  
?>
Exit:
DsSet Object ( [0] = > for) DsSet Object() DsSet Object ([0] = > Geeks [1] = > GFG [2] = > Abc)
Link: https://www.php.net/manual/en/ds-set.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