xref: /PHP-8.2/ext/standard/tests/array/bug21918.phpt (revision f8d79582)
1--TEST--
2Bug #21918 (different handling of positive vs. negative array indexes)
3--FILE--
4<?php
5
6echo "==Mixed==\n";
7$a = array(-1=>'a', '-2'=>'b', 3=>'c', '4'=>'d', 5=>'e', '6001'=>'f', '07'=>'g');
8
9foreach($a as $k => $v) {
10    var_dump($k);
11    var_dump($v);
12}
13
14echo "==Normal==\n";
15$b = array();
16$b[] = 'a';
17
18foreach($b as $k => $v) {
19    var_dump($k);
20    var_dump($v);
21}
22
23echo "==Negative==\n";
24$c = array('-2' => 'a');
25
26foreach($c as $k => $v) {
27    var_dump($k);
28    var_dump($v);
29}
30
31?>
32--EXPECT--
33==Mixed==
34int(-1)
35string(1) "a"
36int(-2)
37string(1) "b"
38int(3)
39string(1) "c"
40int(4)
41string(1) "d"
42int(5)
43string(1) "e"
44int(6001)
45string(1) "f"
46string(2) "07"
47string(1) "g"
48==Normal==
49int(0)
50string(1) "a"
51==Negative==
52int(-2)
53string(1) "a"
54