ArrayObject::offsetGet


Returns the value at the specified index.



<?php

mix 
public ArrayObject::offsetGet mix $index )


where,

$index The index to get the value

?>

$index


The index to get the value.



 ATTENTION 


This function returns the value at the specified index or NULL.

If the $index does not exist, an E_NOTICE is issued.



  1 EXERCISE   

<?php

$arrcolor 
= new ArrayObject([ 'CMYK''cyan''magenta''yellow''four' => 'black']);

foreach(
$arrcolor as $k => $key)
{

echo 
'[ ' $k ' ] - ';
var_dump($arrcolor->offsetGet($k));
echo 
'<br><br>';

}

?>

 RESULT   

[ 0 ] - string(4) "CMYK"

[ 1 ] - string(4) "cyan""

[ 2 ] - string(7) "magenta""

[ 3 ] - string(6) "yellow""

[ four ] - string(5) "black"


  2 EXERCISE   

<?php

$arrcolor 
= new ArrayObject([ 'CMYK''cyan''magenta''yellow''four' => 'black']);

$arrcolor->offsetSet('RGB', ['red''green''blue']);

foreach(
$arrcolor as $k => $key)
{

echo 
'[ ' $k ' ] - ';
var_dump($arrcolor->offsetGet($k));
echo 
'<br><br>';

}

?>

 RESULT   

[ 0 ] - string(4) "CMYK"

[ 1 ] - string(4) "cyan""

[ 2 ] - string(7) "magenta""

[ 3 ] - string(6) "yellow""

[ four ] - string(5) "black"

[ RGB ] - array(3) { [0]=> string(3) "red" [1]=> string(5) "green" [2]=> string(4) "blue" }