Re: How do I write a compound variable?

From: Date: Tue, 07 Aug 2001 00:17:36 +0000
Subject: Re: How do I write a compound variable?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61517@lists.php.net to get a copy of this message
try for ($year=1995;$year<=2001;$year++) { $high = "high_" . $year; $low = "low_" . $year; printf("avg for %s is %s",$year,($high + $low)/2); } on 8/6/01 5:50 PM, Hugh Danaher at hdanaher@earthlink.net wrote: > I want to do a simple FOR statement where I average the high and low value for > a given year. A user will > input the values on a separate page and hit a submit button. I can hard code > each year to do what I want, but I'd like a simpler method. I've tried > variations of multiple $'s, +'s and quote marks but haven't hit on the correct > method, and I could certainly use someone's help. > > Thanks, > Hugh > > > What I want to do: > <?php > > $high_1995=22; > $high_1996=23; > $high_1997=20; > $high_1998=18; > $high_1999=20; > $high_2000=21; > $high_2001=23; > > $low_1995=22; > $low_1996=23; > $low_1997=20; > $low_1998=18; > $low_1999=20; > $low_2000=21; > $low_2001=23; > > for ($year=1995;$year<=2001;$year++) > { > $avg_$year=($high_$year"+$low_$year)/2 // create $avg_1995, ... > print "$avg_$year<br>"; > } > > ?> > -- mike cullerton

« previous php.general (#61517) next »