Re: Problems with globals...
| From: | Chris Murley | Date: | Tue, 25 Jul 2000 15:55:41 +0000 |
| Subject: | Re: Problems with globals... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8070@lists.php.net to get a copy of this message | ||
do this:
make it global for use in the function, before you try to manupliate it
> function stringsToLower( $stringsArray ) {
> global $stringVariable;
> for( $elNum = 0; $elNum < count( $stringsArray ); $elNum++ ) {
>
> $stringVariable = $stringsArray[$elNum];
>
>
> $stringVariable = strtolower( $$stringVariable );
>
> }
> }
On Tue, 25 Jul 2000, Boget, Chris wrote:
> 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>