PHP - Manual: ArrayAccess::offsetSet
2024-11-13
(PHP 5, PHP 7, PHP 8)
ArrayAccess::offsetSet — 设置一个偏移位置的值
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()。 只有该方法通过引用返回,操作才会成功。
官方地址:https://www.php.net/manual/en/arrayaccess.offsetset.php