PHP中ArrayObject类的offsetGet()函数用于获取ArrayObject上特定索引处的值。
用法:
mixed offsetGet($index)
参数:此函数接受单个参数$index,将为其返回相应的值。
Return Value:此函数返回ArrayObject中指定索引处的值。
以下示例程序旨在说明上述功能:
程序1::
// PHP program to illustrate the
// offsetGet() function
$arr = array("geeks100", "geeks99", "geeks1", "geeks02");
// Create array object
$arrObject = new ArrayObject($arr);
// Value present at index 1
echo "".($arrObject->offsetGet(1));
// Value present at index 3
echo "\n".($arrObject->offsetGet(3));
// Value present at index 0
echo "\n".($arrObject->offsetGet(0));
?>
输出:
geeks99
geeks02
geeks100
程序2::
// PHP program to illustrate the
// offsetGet() function
$arr = array("Welcome"=>"1", "to" => "2", "GfG" => "3");
// Create array object
$arrObject = new ArrayObject($arr);
// Print the value at index "Welcome"
echo $arrObject->offsetGet("Welcome");
// Print the value at index "to"
echo "\n".$arrObject->offsetGet("to");
?>
输出:
1
2