Deprecated: Optional parameter $keys declared before required parameter $cms_id is implicitly treated as a required parameter in /home/www/dev/work/class/blog/CmsKey.php on line 75

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$title is deprecated in /home/www/dev/work/website/lvesu/class/controller/blog/php.php on line 28

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$outlink is deprecated in /home/www/dev/work/website/lvesu/template/blog/cms/php.manual.tpl on line 2

Deprecated: Creation of dynamic property lvesu\lvesu\controller\blog\php::$status is deprecated in /home/www/dev/work/website/lvesu/template/blog/index.head.php on line 2
PHP - Manual: ArrayAccess::offsetGet - 互联网笔记

略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ArrayAccess::offsetGet

2025-04-27

ArrayAccess::offsetGet

(PHP 5, PHP 7, PHP 8)

ArrayAccess::offsetGet获取一个偏移位置的值

说明

public ArrayAccess::offsetGet(mixed $offset): mixed

返回指定偏移位置的值。

当检查一个偏移位置是否为 empty() 时,会执行此方法。

参数

offset

需要获取的偏移位置。

返回值

可返回任何类型。

注释

注意:

此方法的实现可以通过引用返回。 这使得可以间接修改 ArrayAccess 对象,能够重载数组的维度。

直接修改是完全替代数组维度的值,例如 $obj[6] = 7。 另一方面,间接修改是指仅修改某个维度中的一部分,或者传引用的方式赋值一个维度, 例如 $obj[6][7] = 7$var =& $obj[6]。 使用 ++ 自增或者使用 -- 自减也是通过间接修改的方式实现的。

直接修改会触发对 ArrayAccess::offsetSet() 的调用,而间接修改则会触发对 ArrayAccess::offsetGet() 的调用。在这种情况下, ArrayAccess::offsetGet() 的实现必须能通过引用返回,否则会引发 E_NOTICE 消息。

参见

添加备注

用户贡献的备注

此页面尚无用户贡献的备注。

官方地址:https://www.php.net/manual/en/arrayaccess.offsetget.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3