How can foreach loop affect session variable?
session_start();
$_SESSION[test] = "Session content";
echo $_SESSION[test].'<br />';
$test_array = array("test", "array", "something", "array end");
foreach($test_array as $test){
echo $test.'<br />';
}
echo '<br />Session content after foreach: '.$_SESSION[test].'<br />';
When I run this code on some web hostings, its output is OK.
Session content
test
array
something
array end
Session content after foreach: Session content
But only at first execution (when session is created). When I execute this code second time (session is already created) its output looks like this:
Session content
test
array
something
array end
Session content after foreach: array end
I don't know how can variable $test affect $_SESSION[test].