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!
What Is a Hyphen? A hyphen (-) is a punctuation mark that’s used to join words or parts of words. It’s not interchangeable with other types of dashes. Use a hyphen in a compound modifier when the modifier comes before the word it’s modifying. If you’re not sure whether a compound word has a hyphen or not, check your preferred dictionary.
Hyphenated Compound Words. Hyphenated compound words are the ones (obviously) with a hyphen between the words. Over time, many hyphenated compounds become closed compounds—teen-ager became teenager for instance. Check a dictionary if you’re not sure whether to use a hyphen or not.
When you write out a number in words, you should use hyphens to show a link between the number words (e.g. “There are ninety-nine people invited.”) When the end of a line comes in the middle of a word, you can use a hyphen to divide it in a way it normally wouldn’t be.
For example, in the phrase “up-to-date technology,” we hyphenate “up-to-date” to signal that these three words are to be read as one concept, or adjective, functioning to modify the word “technology.” One easy way to tell if you should use a hyphen is to pair each describing word on its own with the noun it’s describing.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With