Tuesday, November 19, 2024
Google search engine
HomeLanguagesPHP | DsSequence get() Function

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:




<?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));
  
?>


Output:

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

Program 2:




<?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));
}
  
?>


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

RELATED ARTICLES

Most Popular

Recent Comments