The skip() function of PHP Ds\Map class is used to get a key-value pair present at a specific index in the Map instance. The index is passed as a parameter to the function and the function returns the Pair present at that index in the map.
Note: The index passed in the parameter is 0-based. That is the elements starts from the index 0.
Syntax:
public Ds\Map::skip(int $index)
Parameters: This function accepts a single parameter $index which is the index from which the key-value pair is needed to be returned.
Return Value: The function returns a pair of type Ds\Pair which is the key-value pair in the Map instance present at the index specified by the parameter $index.
Below programs illustrate the skip() function:
Program 1:
<?php
$map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30,
4 => 40, 5 => 50, 6 => 60]);
print_r( $map ->skip(3));
?>
|
Output:
Ds\Pair Object
(
[key] => 4
[value] => 40
)
Program 2:
<?php
$map = new \Ds\Map([ "first" => "Geeks" , "second" => "for" ,
"third" => "Geeks" ]);
print_r( $map ->skip(1));
?>
|
Output:
Ds\Pair Object
(
[key] => second
[value] => for
)
Reference: http://php.net/manual/en/ds-map.skip.php
Last Updated :
30 Jan, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...