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()。 只有该方法通过引用返回,操作才会成功。

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top