I want to create a session variable but the session variable name I want to be dynamic. So what I need is the proper syntax for a variable name that is a $_SESSION variable.
I have tried the code below which creates a variable variable name and stored a value to it and it works just fine.
$xvalue = $_SESSION['delivery_id'];
$delivery_string = 'this_delivery_id_' . $xvalue ;
$$delivery_string = $_SESSION['delivery_id'];
echo "Variable name: " . $delivery_string . "<br/>";
echo "Session Variable Value: " . $this_delivery_id_29 . "<br/>";
The above code echos 29 for line 5; the desired result.
So working upon what worked with a variable variable I then just tried to make the variable name a $_SESSION variable name instead.
$value = $_SESSION['delivery_id'];
$xsession = "$_SESSION[\"" . $value . "\"]"; // this gives compilation error so dead stop. I also tried without the escapes and also a dead stop. I also tried escaping the [ and ] and got rid of the compilation error so the code runs but it does not give the desired result.
$$xsession = $_SESSION['delivery_id'];
echo "Variable name: " . $xsession . "<br/>";
echo "Session Variable Value: " . $_SESSION["delivery_id_29"] . "<br/>";
So line 2 of the code is where the problem is.
$in"$_SESSION[\"" . $value . "\"]"-"\$_SESSION[\"" . $value . "\"]"$_SESSION['order_setup'] = ['2019-06-04' => ['foo-123']], or if I had 3 items to arrive on two different days, I may have:$_SESSION['order_setup'] = ['2019-06-04' => ['foo-123'], '2019-06-05' => ['bar-987', 'baz-456']]. It's a much simpler approach without varvars, and somewhat easier to iterate over.