How do I write a compound variable?
| From: | Hugh Danaher | Date: | Mon, 06 Aug 2001 23:50:54 +0000 |
| Subject: | How do I write a compound variable? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-61514@lists.php.net to get a copy of this message | ||
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>";
}
?>