I want to use a string variable as an array key
for example:
$var = "hello"; $myarray['hello'] = "hi there"; echo "output is ".$myarray['$var'];
doesn't work - it just does:
output is
I can't find anything in the manual - any ideas?
TIA
Julia
Here you go Julia...
$var = "Hello"; // To make the array, choose one below: $array = array($var => "Hi There"); // OR $array[$var] = "Hi There"; // OR $array['Hello'] = "Hi There"; //Confirm array's key/value content with this: (Not required, this is just so you can see what's going on) print_r($array); // Output by either of these methods below: echo "Output is: ".$array['Hello']; // OR echo "Output is: ".$array[$var];
thanks, the problem was with the inverted commas