xref: /PHP-8.4/Zend/tests/gh11244-005.phpt (revision cd53ce83)
1--TEST--
2GH-11244: Modifying a copied by-ref iterated array resets the array position (multiple copies)
3--FILE--
4<?php
5
6$data = [0, 1, 2];
7
8foreach ($data as $key => &$value) {
9    echo "$value\n";
10    if ($value === 1) {
11        $cow_copy = [$data, $data, $data];
12        echo "unset $value\n";
13        unset($cow_copy[0][$key]);
14        unset($data[$key]);
15        unset($cow_copy[2][$key]);
16    }
17}
18
19print_r($cow_copy);
20
21?>
22--EXPECTF--
230
241
25unset 1
262
27Array
28(
29    [0] => Array
30        (
31            [0] => 0
32            [2] => 2
33        )
34
35    [1] => Array
36        (
37            [0] => 0
38            [1] => 1
39            [2] => 2
40        )
41
42    [2] => Array
43        (
44            [0] => 0
45            [2] => 2
46        )
47
48)
49