Monday, June 15, 2026
HomeLanguagesPHP | ArrayIterator offsetGet() Function

PHP | ArrayIterator offsetGet() Function

The ArrayIterator::offsetGet() function is an inbuilt function in PHP which is used to get the value of an offset.

Syntax:

mixed ArrayIterator::offsetGet( mixed $index )

Parameters: This function accepts single parameter $index which holds the offset to get the value from.

Return Value: This function returns the value at offset index.

Below programs illustrate the ArrayIterator::offsetGet() function in PHP:

Program 1:




<?php
  
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array(
        "a" => 4,
        "b" => 2,
        "g" => 8,
        "d" => 6,
        "e" => 1,
        "f" => 9
    )
);
  
// Value present at index "a" 
echo ($arrItr->offsetGet("a")) . " "; 
    
// Value present at index "g"
echo ($arrItr->offsetGet("g")) . " "; 
    
// Value present at index "f"
echo ($arrItr->offsetGet("f")); 
  
?>


Output:

4 8 9

Program 2:




<?php
     
// Declare an ArrayIterator
$arrItr = new ArrayIterator(
    array(
        "for", "Geeks", "Science",
        "Geeks", "Portal", "Computer"
    )
);
  
    
// Print the value at index 1 
echo $arrItr->offsetGet(1) . "\n"; 
    
// Print the value at index 0
echo $arrItr->offsetGet(0) . "\n"; 
  
// Print the value at index 3
echo $arrItr->offsetGet(3); 
  
?>


Output:

Geeks
for
Geeks

Reference: https://www.php.net/manual/en/arrayiterator.offsetget.php

RELATED ARTICLES

Most Popular

Dominic
32516 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS