[php-src] Issue #14968: bug loop in php
| From: | bsv-nhatha | Date: | Tue, 16 Jul 2024 08:20:31 +0000 |
| Subject: | [php-src] Issue #14968: bug loop in php | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247298@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14968
Author: bsv-nhatha
### Description
The following code:
```php
<?php
$value = [
['a' =>'1', 'c' => '2'],
['a' =>'3', 'c' => '4'],
['a' =>'5', 'c' => '6'],
['a' =>'7', 'c' => '7']
];
foreach ($value as $key => &$item) {
$value[$key]['b'] = $item['a'] + $item['c'];
}
foreach ($value as $key => $item) {
$value[$key]['a'] = $item['a'];
}
```
Resulted in this output:
```
array:4 [
0 => array:3 [
"a" => "1"
"c" => "2"
"b" => 3
]
1 => array:3 [
"a" => "3"
"c" => "4"
"b" => 7
]
2 => array:3 [
"a" => "5"
"c" => "6"
"b" => 11
]
3 => & array:3 [
"a" => "5"
"c" => "6"
"b" => 11
]
]
```
But I expected this output instead:
```
array:4 [
0 => array:3 [
"a" => "1"
"c" => "2"
"b" => 3
]
1 => array:3 [
"a" => "3"
"c" => "4"
"b" => 7
]
2 => array:3 [
"a" => "5"
"c" => "6"
"b" => 11
]
3 => & array:3 [
"a" => "7"
"c" => "7"
"b" => 14
]
]
```
### PHP Version
PHP 8.2.20
### Operating System
MAC OS solana 14.5