RE: [PHP] Problems with globals...

From: Date: Tue, 25 Jul 2000 16:31:49 +0000
Subject: RE: [PHP] Problems with globals...
Groups: php.general 
Request: Send a blank email to php-general+get-8081@lists.php.net to get a copy of this message
> > function stringsToLower( $stringsArray ) { > > for( $elNum = 0; $elNum < count( $stringsArray ); $elNum++ ) { > > > > $stringVariable = $stringsArray[$elNum]; > > > > $stringVariable = strtolower( $$stringVariable ); > > > > } > > } > OHH, then remove the global all together... > once you assign $stringVariable, itr will be available outside the > function, or hell, return() if if you want.... Hmm, I don't think I came across correctly that time, either. If I put $stringVariable outside the for() loop, the the value of that variable will be the lowercased value of the last variable in the array that was passed. That's not going to do me any good. I could return the changed array, but then that is yet more code assigning the new values back to the variables. The reason I want to make it global is so I can pass variable names to the function and get the values of all those values lower cased prior to use. I'm trying to avoid this: $thisFormVar = strtolower( $thisFormVar ); $thatFormVar = strtolower( $thatFormVar ); $theOtherFormVar = strtolower( $theOtherFormVar ); $anotherFormVar = strtolower( $anotherFormVar ); etc. etc. etc. $query = INSERT $thisFormVar, $thatFormVar, etc, etc."; As you can see, that is alot of cumbursome code. I'm trying to turn the above into just this: stringsToLower( array( "thisFormVar", "thatFormVar", etc, etc) $query = INSERT $thisFormVar, $thatFormVar, etc, etc."; and just continue on with my code, not worrying about reassigning variables to their modified values; turning X lines of code (where X is the number of variables I need to change) to 2 lines of code. Other- wise, I may as well have just went with the first way above. Thanks again. :) Chris

« previous php.general (#8081) next »