php8.5
Home/ Manual/ ds / vector/ Ds\Vector::copy

Ds\Vector::copy

PHP function Edit on GitHub ✎

(PECL ds >= 1.0.0)

Returns a shallow copy of the vector

Description

Ds\Vector::copy(): Ds\Vector

Returns a shallow copy of the vector.

Parameters Parameters

Return Values

Returns a shallow copy of the vector.

Examples

Ds\Vector::copy() example

php
<?php
$a = new \Ds\Vector([1, 2, 3]);
$b = $a->copy();

// Updating the copy doesn't affect the original
$b->push(4);

print_r($a);
print_r($b);
?>

The above example will output something similar to:

output
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Ds\Vector Object
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
)

Source: reference/ds/ds/vector/copy.xml · from the official PHP manual (php/doc-en)