PHP | Ds\Sequence get() Function

The Ds\Sequence::get() function is an inbuilt function in PHP which returns the value at given index.

Syntax:

mixed abstract public Ds\Sequence::get ( int $index )

Parameter: This function accepts single parameter $index which holds the index to access element.



Return value: This function returns the value at given index.

Below programs illustrate the Ds\Sequence::get() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new sequence
$seq new \Ds\Vector(["G", "E", "E",
        "K", "S", "1", "2", 1, 2, 3, 4]);
  
// Use get() function
var_dump($seq->get(0));
  
// Use get() function
var_dump($seq->get(1));
  
// Use get() function
var_dump($seq->get(10));
  
// Use get() function
var_dump($seq->get(5));
  
// Use get() function
var_dump($seq->get(7));
  
?>

chevron_right


Output:

string(1) "G"
string(1) "E"
int(4)
string(1) "1"
int(1)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Create new sequence
$seq new \Ds\Vector(["G", "E", "E",
        "K", "S", "1", "2", 1, 2, 3, 4]);
  
// Declare an index array
$arr = array (0, 1, 4, 6, 8, 5);
  
// Loop run for every array element  
foreach ($arr as $val) {  
  
    // Use get() function
    var_dump($seq->get($val));
}
  
?>

chevron_right


Output:

string(1) "G"
string(1) "E"
string(1) "S"
string(1) "2"
int(2)
string(1) "1"

Reference: http://php.net/manual/en/ds-sequence.get.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.