-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Description
The following code:
<?php
$aaa = [[1,2,3,4]];
$i = 5;
foreach ($aaa as &$aa) {
foreach ($aa as &$a) {
$a = $i;
$i--;
}
}
var_dump ($aaa);
foreach ($aaa as &$aa) {
foreach ($aa as $a) {
}
}
var_dump ($aaa);Resulted in this output:
array(1) {
[0]=>
&array(4) {
[0]=>
int(5)
[1]=>
int(4)
[2]=>
int(3)
[3]=>
&int(2)
}
}
array(1) {
[0]=>
&array(4) {
[0]=>
int(5)
[1]=>
int(4)
[2]=>
int(3)
[3]=>
&int(3)
}
}
But I expected at least this output instead:
array(1) {
[0]=>
&array(4) {
[0]=>
int(5)
[1]=>
int(4)
[2]=>
int(3)
[3]=>
int(2)
}
}
array(1) {
[0]=>
&array(4) {
[0]=>
int(5)
[1]=>
int(4)
[2]=>
int(3)
[3]=>
int(2)
}
}
Played the script with different versions on
https://onlinephp.io?s=s7EvyCjg5eLlUklMTFSwVYiONtQx0jHWMYmNtQYKZgKFTIGMtPyi1MTkDAUNsLLEYgU1IENToZqXixNZCioDkeBUARmokmkNZmfq6oIYtbxctSDryhKL4lNKcwsgJmqSZgXMBohhmEaBoIKCAogCAA%2C%2C&v=8.4.10
PHP Version
PHP Version => 8.4.10
Zend Engine v4.4.10, Copyright (c) Zend Technologies
Build Date => Jul 13 2025 00:21:23
Build System => Linux 4.14.290-217.505.amzn2.x86_64 #1 SMP Wed Aug 10 09:52:16 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Operating System
Linux 5.10.214-202.855.amzn2.x86_64 #1 SMP Tue Apr 9 06:57:12 UTC 2024 x86_64