Problems with globals...
| From: | Boget, Chris | Date: | Tue, 25 Jul 2000 16:03:13 +0000 |
| Subject: | Problems with globals... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-8068@lists.php.net to get a copy of this message | ||
Consider the following code:
function stringsToLower( $stringsArray ) {
for( $elNum = 0; $elNum < count( $stringsArray ); $elNum++ ) {
$stringVariable = $stringsArray[$elNum];
global $stringVariable;
$stringVariable = strtolower( $$stringVariable );
}
}
$joe = "This";
$bob = "That";
$briggs = "Other";
echo "Before: $joe $bob $briggs<br>\n";
stringsToLower( array( "joe", "bob", "briggs" ));
echo "After: $joe $bob $briggs<br>\n";
Pretty easy to figure out what it does. I need something like this
because there is going to be *alot* of this kind of conversion.
Now, the problem I'm getting in on the line:
$strVariable = $stringsArray[$elNum];
global $strVariable; <--- error here
generates an error saying that $strVariable is already assigned or
somesuch. I've also tried things like:
global $stringsArray[$elNum];
But that gives me a parse error.
Is there any way I can do what I need? I know I cannot get the
actual names of the variables (*grumble* :p), but aside from my
above sample code, I don't know of any other way to do something
like this...
Any help would be appreciated!!
Chris