Re: Problems with globals...
| From: | Daniel Convissor | Date: | Tue, 25 Jul 2000 16:34:21 +0000 |
| Subject: | Re: Problems with globals... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8082@lists.php.net to get a copy of this message | ||
Hey Chris:
Several problems in the test. The array created just had an enumerated
index. Also, the results in the "After" section were looking at the initial
variables, not the stuff you stuck into the array and ran through the
function.
function stringsToLower( $stringsArray ) {
while ( list($Key,$Val) = each($stringsArray ) ) {
global $$Key;
$$Key = strtolower($Val);
}
}
$joe = "This";
$bob = "That";
$briggs = "Other";
echo "Before: $joe $bob $briggs<br>\n";
$Blah = array( "joe"=>"$joe", "bob"=>"$bob",
"briggs"=>"$briggs" );
stringsToLower( $Blah );
echo "<p>After: $joe $bob $briggs<br>\n";
Things that are different:
* Created associative index on the array.
* Switch to while/list/each rather than a count(), far simpler.
* "global $$Key;" rather than just "global $Key;"
This process seems kind of overblown. I mean, why are you making an array to
check this? It'd be much simpler to just run your variables through the
strtolower() directly
$briggs = strtolower($briggs);
rather than having to create an array to then check. Perhaps the incoming
info is already in an array?
Enjoy,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409