teravice teravice - 1 year ago 58
PHP Question

Difference between $_session[''] & $_session[""] in php

I searched but didn't find a question about this. Is there a difference between

in PHP?

I know the difference of single and double quotes at the echo command but can't figure out the above. At my testing server it works fine both ways, but is there something deeper?

Answer Source

Difference is as follows:-

Eg: $key = 'demo';
In single quote, 
$_SESSION['$key'] = $key; wont work.
But in double quotes,
$_SESSION["$key"] = $key; works.

Means you can pass php variable directly in double quotes but not in single quote.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download