Re: Variables with - in their name

From: Date: Sun, 18 Nov 2012 11:12:25 +0000
Subject: Re: Variables with - in their name
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-319732@lists.php.net to get a copy of this message
On Sun, 2012-11-18 at 01:37 -0700, Nathan Nobbe wrote: > On Sat, Nov 17, 2012 at 11:09 PM, Ron Piggott < > ron.piggott@actsministries.org> wrote: > > > I have made the following variable in a form: (I am referring the > > <select> ) > > > > <?php > > > > $row['promo_code_prefix'] = 42; > > $row['promo_code_suffix'] = 2; > > > > echo "<select name=\"distributor-" . $row['promo_code_prefix'] > > . "-" .. > > $row['promo_code_suffix'] . "\" style=\"text-align: > > center;\">\r\n"; > > > > ?> > > > > It could be wrote: > > > > <?php > > > > echo $distributor-42-2; > > > > ?> > > > > Only PHP is treating the hyphen as a minus sign --- which in turn is > > causing a syntax error. > > > > How do I retrieve the value of this variable and over come the “minus” > > sign that is really a hyphen? > > > > php > ${distributor-42-2} = 5; > php > echo ${distributor-42-2}; > 5 > > I think that's it. > > -nathan I'd just try and avoid the hyphens in the variable names in the first place if you can. Can you guarantee that everyone working on this system will know when to encapsulate the variables in braces? Thanks, Ash http://www.ashleysheridan.co.uk

« previous php.general (#319732) next »