哈希空间 Ctrl + F 进行搜索
首页 php手册中文版 CSS中文手册 哈希文档 Markdown在线工具

ArrayAccess::offsetSet

(PHP 5, PHP 7, PHP 8)

ArrayAccess::offsetSet设置一个偏移位置的值

说明

public ArrayAccess::offsetSet(mixed $offset, mixed $value): void

为指定的偏移位置设置一个值。

参数

offset

待设置的偏移位置。

value

需要设置的值。

返回值

没有返回值。

注释

注意:

如果另一个值不可用,那么 offset 参数将被设置为 null,就像下面的例子。

<?php
$arrayaccess
[] = "first value";
$arrayaccess[] = "second value";
print_r($arrayaccess);
?>

以上例程会输出:

Array
(
    [0] => first value
    [1] => second value
)

注意:

This function is not called in assignments by reference and otherwise indirect changes to array dimensions overloaded with ArrayAccess (indirect in the sense they are made not by changing the dimension directly, but by changing a sub-dimension or sub-property or assigning the array dimension by reference to another variable). 而是调用 ArrayAccess::offsetGet()。 只有该方法通过引用返回,操作才会成功。

打开 哈希空间 微信小程序中查看更佳