Change language

PHP Ds / Map slice () Function

Syntax:
public DsMap::slice (int $index, int $length) 
Parameter:this the function takes two parameters, as described below:
  • $index:This parameter specifies the index from which the elements will be returned in the subset. This parameter can be either positive or negative. If the $index is positive, then the range is calculated from the beginning of the map, and if it is negative, the index is positioned from the end.
  • $length:This parameter is optional. If length $is not specified, then the elements in the subset will be from the start index to the end of the map. If length is specified, then the returned subset will contain elements starting at $index in the Map and ending with the specified length. For example, if $index = 2 and $length = 4, then the subset will contain 4 elements, starting with the element represented at index 2 in the actual Map instance.
Returned value: The Program 1:
// PHP program to illustrate the slice() function $map = new DsMap ([1 = > 10, 2 = > 20, 3 = > 30, 4 = > 40.5 = > 5 0.6 = > 60]);  
// when the index is positive and the length is not
// specified print_r ( $map -> slice (4));  
// when the index is negative and the length is not
// specified print_r ( $map -> slice (-4));  
?>
Output:
DsMap Object ([0] = > DsPair Object ([key] = > 5 [value] = > 50) [1] = > DsPair Object ([key] = > 6 [value] = > 60)) DsMap Object ([0] = > DsPair Object ([key] = > 3 [value] = > 30) [1] = > DsPair Object ([key] = > 4 [ value] = > 40) [2] = > DsPair Object ([key] = > 5 [value] = > 50) [3] = > DsPair Object ([key] = > 6 [value] = > 60)) 
Program 2:
// PHP program to illustrate the slice() function $map = new DsMap ([1 = > 10, 2 = > 20, 3 = > 30, 4 = > 40.5 = > 50.6 = > 60]);  
// when the index is positive and the length // specified print_r ( $map -> slice (2, 2));  
// when the index is negative and the length
// specified print_r ( $map -> slice (-2, 2));  
?>
Output:
DsMap Object ([0] = > DsPair Object ([key] = > 3 [value] = > 30) [1] = > DsPair Object ([key] = > 4 [value] = > 40)) DsMap Object ([0] = > DsPair Object ([key] = > 5 [value] = > 50) [1] = > DsPair Object ([key] = > 6 [ value] = > 60)) 
Link : http://php.net/manual/en/ds-map.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