Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- heredocs and numbers in indexes
November 15, 2008, 4:27 pm
rate this thread
$array['1a'] = 'something';
$array['a1'] = 'something else';
I can do this: echo $array['1a'];
And I can do this:
But if the index starts with a digit, php fails looking for the trailing
Why is that? Is there a fix other than renaming the indexes?
or does not work.
Is this a bug or is it a feature I don't understand?
- Thomas Mlynarczyk
November 15, 2008, 5:34 pm
Re: heredocs and numbers in indexes
Because PHP (like most languages) makes its decision on whether a value
is a number or a string based on the first character. In this case you
must still use single quotes around the '1a' - or PHP will try to
interpret it as a numeric index.
Just because you use heredoc doesn't mean you can get rid of *all*
quotes - just many of them. You still need to be aware of what's going on.
Remove the "x" from my email address
JDS Computer Training Corp.