Hi, I'm trying to create a session array and give a dynamic name.
I tried something like this but I get only the last entry i made (key=0) :
-
$qid = $_POST['pstq'];
-
$_SESSION[$qid] = array();
-
-
foreach ($_SESSION[$qid] as $key=>$value) {
-
echo "<table><tr><td> $key : </td><td>$value</td></tr>
-
}
-
and i get this notice
-
Notice: Unknown: Skipping numeric key 0. in Unknown on line 0
-
of course I start the session etc.
Thnx.
Hi. Welcome to The Scripts!
The obvious error there is the missing quote-mark and semi-colon at the end of the echo statement. But, assuming that is a typo I would point out that your new $_SESSION[$qid] array is initialized each time you run the scripts as an empty array, which would presumably cause the foreach loop to be skipped entirely.
I can see no reason for the notice, however.
I did try something similar myself, which executed without warnings and gave me the results I expected:
-
<?php
-
session_start();
-
-
$qid = "pstg";
-
$_SESSION[$qid] = array("one" => 1, 2 => "Two");
-
-
echo "<pre>";
-
print_r($_SESSION);
-
echo "</pre>";
-
?>
-