Open In App

PHP | Ds\skip() Function

Improve
Improve
Like Article
Like
Save
Share
Report

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
// PHP program to illustrate skip() function
  
$map = new \Ds\Map([1 => 10, 2 => 20, 3 => 30,
            4 => 40, 5 => 50, 6 => 60]);
  
// Key-Value pair present at index 3
print_r($map->skip(3));
  
?>


Output:

Ds\Pair Object
(
    [key] => 4
    [value] => 40
)

Program 2:




<?php
// PHP program to illustrate skip() function
  
$map = new \Ds\Map(["first" => "Geeks", "second" => "for"
                                "third" => "Geeks"]);
  
// Key-Value pair present at index 1
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
Previous
Next
Share your thoughts in the comments
Similar Reads