略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pht\Vector::updateAt

2024-12-26

pht\Vector::updateAt

(PECL pht >= 0.0.1)

pht\Vector::updateAtUpdates a value in the vector

说明

public pht\Vector::updateAt ( mixed $value , int $offset ) : void

This method updates a value at the specified offset in the vector (in linear time). The vector will automatically be resized if it is not large enough.

Since the pht\Vector class supports array access, updating values can also be performed using the array subset notation ([]).

参数

value

The value to be inserted into the vector. This value will be serialised (since it may be passed around between threads).

offset

The offset at which the value will be updated at. This offset must be within the 0..(N-1) range (inclusive), where N is the size of the vector. Attempting to update at offsets outside of this range will result in an Error exception.

返回值

No return value.

范例

Example #1 Updating a value in a vector

<?php

use pht\Vector;

$vector = new Vector();

$vector[] = 1;
$vector[] = 2;

$vector->updateAt(30);
$vector[1] = 4;

var_dump($vector);

以上例程会输出:

object(pht\Vector)#1 (2) {
  [0]=>
  int(3)
  [1]=>
  int(4)
}
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/pht-vector.updateAt.php

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