xref: /PHP-8.2/Zend/tests/bug68215.phpt (revision f8d79582)
1--TEST--
2Bug #68215 (Behavior of foreach has changed)
3--FILE--
4<?php
5$arr = array(
6    'a' => array(
7        'a' => 'apple',
8        'b' => 'banana',
9        'c' => 'cranberry',
10        'd' => 'mango',
11        'e' => 'pineapple'
12    ),
13    'b' => array(
14        'a' => 'apple',
15        'b' => 'banana',
16        'c' => 'cranberry',
17        'd' => 'mango',
18        'e' => 'pineapple'
19    ),
20    'c' => 'cranberry',
21    'd' => 'mango',
22    'e' => 'pineapple'
23);
24
25function test(&$child, $entry)
26{
27    $i = 1;
28
29    foreach ($child AS $key => $fruit)
30    {
31        if (!is_numeric($key))
32        {
33            $child[$i] = $fruit;
34            unset($child[$key]);
35            $i++;
36        }
37    }
38}
39
40$i = 1;
41
42foreach ($arr AS $key => $fruit)
43{
44    $arr[$i] = $fruit;
45
46    if (is_array($fruit))
47    {
48        test($arr[$i], $fruit);
49    }
50
51    unset($arr[$key]);
52    $i++;
53}
54
55var_dump($arr);
56?>
57--EXPECT--
58array(5) {
59  [1]=>
60  array(5) {
61    [1]=>
62    string(5) "apple"
63    [2]=>
64    string(6) "banana"
65    [3]=>
66    string(9) "cranberry"
67    [4]=>
68    string(5) "mango"
69    [5]=>
70    string(9) "pineapple"
71  }
72  [2]=>
73  array(5) {
74    [1]=>
75    string(5) "apple"
76    [2]=>
77    string(6) "banana"
78    [3]=>
79    string(9) "cranberry"
80    [4]=>
81    string(5) "mango"
82    [5]=>
83    string(9) "pineapple"
84  }
85  [3]=>
86  string(9) "cranberry"
87  [4]=>
88  string(5) "mango"
89  [5]=>
90  string(9) "pineapple"
91}
92