13

If for example you had an associative array which looked something like this:

$array = array('first-value' => 'Hello');

And you were then to extract it:

extract($array);

How would you access "first-value" as hyphens cannot be used in variable names? Is the hyphen replaced with another character?

I have tried the following with no luck...

echo ${'first-value'};
echo $first_value;
echo $firstvalue;

Couldn't even find an mention of this in the Php manual...

Thanks in advance!

smilly92
  • 2,383
  • 1
  • 23
  • 43

1 Answers1

15

If you do echo extract($array);, you can see that it outputs 0, which is the number of variables successfully imported into the symbol table. In other words, the variable can not be imported because of the hyphen and thus does not exist.

Tatu Ulmanen
  • 123,288
  • 34
  • 187
  • 185