Some Query About Associative Arrays in PHP

I have a question about associative arrays in PHP.

I have following associative array Where "data" is the key of that array.

$_SESSION['data'] = 1;

Now, I want to declare "data" as a variable. Like this-

 $data=id;

 $_SESSION['$data'] = 1;
  
 echo $_SESSION['id'];

Is it even possible to do that ?? Or, I'm doing it in the wrong way ??

Any Help Would Be Appreciated. Thank u.

Answer

Solution:

All is okay, just use variable without qoutes:

$data = 'id';
// no quotes here
$_SESSION[$data] = 1;
echo $_SESSION['id'];

Source