Jump to content

Very Simple Question


amrita

Recommended Posts

I reasonly discovered that is it not possible to name your variable starting with a number e.g. $3name - I wondered why?Is there another function of $(any number) since it's not possible?I'm still new at php and exploring things - does anyone know?

Link to comment
Share on other sites

In c++ and some other languages identifiers starting with a number and following some letters are used for something else. For exampledouble number = 2d; //assign a double value to a double variablelet's say that we can name an identifier starting with a number:double 2d = 2d;if(2d==2d)isn't this messed up?? how do we know which one is a variable and which one is a number?aslo 0x... is used for hex values.Since php variables start with $ sign, the situation might be different, but still they have the same rule.you can use for example $_3nameHope it helped.

Link to comment
Share on other sites

As with PHP's predecessor, Perl, in some contexts $1 etc. are used as backreferences to captured strings inside regular expressions. See here for instance: http://us2.php.net/manual/en/function.preg-replace.phpI don't know why the PHP parser couldn't distinguish between, say, $1 and $1apple. Perhaps the minor inconvenience exists to keep sleepy programmers from making a potentially costly blunder.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...