dynamically creating variable names
| From: | Lee P Reilly | Date: | Wed, 26 Jun 2002 17:04:04 +0000 |
| Subject: | dynamically creating variable names | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-104004@lists.php.net to get a copy of this message | ||
Hi,
Can someone tell me if it's possible to create variable names from
varaible names? I could work around this problem using some if/else
statements, but I'm interested to see if there's another solution.
I have 20 associative arrays all named compA, compB, compF, etc. The
user supplies a string e.g. "YB"...
// one of the 20 arrays
$compY = array ( // Y Tyr Tyrosine
"H" => 9
,"X" => 2
,"C" => 9
,"N" => 1
,"O" => 2
,"S" => 0
);
$sequence = "YB";
$sequence = strtoupper ($sequence);
for ($i = strlen($sequence)-1; $i >= 0; $i--)
{
// create a temp variable called comp + $i
// e.g. on first iteration access the array, $compB
// and on the second, access $compY
}
Thanks very much in advance.
- Best regards,
Lee Reilly