Arthur,
Thank you very much for your help.  I tried it and it works perfectly.

I haven't tried the array yet though, I'm a bit shy of them as I don't know
much about accessing arrays yet.  Perhaps in the future.
Thank you again.
Hugh
----- Original Message -----
From: Arthur <[EMAIL PROTECTED]>
To: Hugh Danaher <[EMAIL PROTECTED]>
Sent: Monday, August 06, 2001 5:41 PM
Subject: Re: [PHP] How do I write a compound variable?


> To make your code work use curly braces for the compound variables.
>
> http://www.php.net/manual/en/language.variables.variable.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>";
>   }
>
>
> To do it without compound variables do this:
>
> $arr = array(
> 1995 => array(high=>22,low=>22),
> 1996 => array(high=>23,low=>23),
> 1997 => array(high=>20,low=>20),
> 1998 => array(high=>18,low=>18),
> 1999 => array(high=>20,low=>20),
> 2000 => array(high=>21,low=>21),
> 2001 => array(high=>23,low=>24),
> );
>
> foreach($arr as $year=>$vals){
> $avg = ( $vals["high"] + $vals["low"] ) / 2;
> echo $year . " - " . $vals["high"] . " - " . $vals["low"] . " - " . $avg .
> "<br>\n";
> }
>
>
>
> - Arthur
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to