PHP | ArrayIterator offsetGet() Function
Last Updated :
21 Nov, 2019
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
$arrItr = new ArrayIterator(
array (
"a" => 4,
"b" => 2,
"g" => 8,
"d" => 6,
"e" => 1,
"f" => 9
)
);
echo ( $arrItr ->offsetGet( "a" )) . " " ;
echo ( $arrItr ->offsetGet( "g" )) . " " ;
echo ( $arrItr ->offsetGet( "f" ));
?>
|
Program 2:
<?php
$arrItr = new ArrayIterator(
array (
"for" , "Geeks" , "Science" ,
"Geeks" , "Portal" , "Computer"
)
);
echo $arrItr ->offsetGet(1) . "\n" ;
echo $arrItr ->offsetGet(0) . "\n" ;
echo $arrItr ->offsetGet(3);
?>
|
Reference: https://www.php.net/manual/en/arrayiterator.offsetget.php
Share your thoughts in the comments
Please Login to comment...