I'm currently working on a website for my project, but for some reason when everything is as it has to be ( session is started, session variable is defined ), then only array_push() function doesn't add the value to session variable, when I move array_push() out of if, foreach and if (if contains foreach and foreach contains another if), it works fine, I already tried to put it to first if, then to foreach but it didn't help. So it works only when it is out of that code (When it is not in that if, which contains foreach, which contains another if). Please try to understand, my English is not well.
What do I have to do to fix it?
if(isset($_GET["setLang"])) {
foreach ($languages as $item) {
if($item === $_GET["setLang"]) {
$_SESSION["selLang"] = $item;
array_push($_SESSION["sessionMessage"], "Language changed successfully!");
header("location: index.php?path=/");
exit();
}
}
}
$_SESSION["sessionMessage"]really an array?