[php-src] Issue #13236: Variable for each element of array in foreach loop is accessible out of foreach scope.
| From: | jaygajjar40 | Date: | Wed, 24 Jan 2024 05:35:07 +0000 |
| Subject: | [php-src] Issue #13236: Variable for each element of array in foreach loop is accessible out of foreach scope. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246327@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13236
Author: jaygajjar40
### Description
In below code you can see $key and $value are accessible out of scope of foreach loop
The following code:
`<?php
// Enter your code here, enjoy!
$array = array("1" => "PHP code",
"Random number" => rand(100,999),
"PHP Version" => phpversion()
);
foreach( $array as $key => $value ){
echo $key."\t=>\t".$value."\n";
}
echo $key.$value ;
`
Resulted in this output:
```
1 => PHP code
Random number => 953
PHP Version => 8.2.13
PHP Version8.2.13
```
But I expected this output instead:
```
1 => PHP code
Random number => 953
PHP Version => 8.2.13
```
### PHP Version
8.2.13
### Operating System
_No response_