ArrayAccess::offsetSet
(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()。 只有該方法通過引用返回,操作才會成功。