Re: Using a variable to select what variable to use...???

From: Date: Fri, 26 Jan 2001 20:25:11 +0000
Subject: Re: Using a variable to select what variable to use...???
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-36863@lists.php.net to get a copy of this message
At 9:32 AM -0800 1/26/01, Brandon Orther wrote:
Hello, I am doing a do loop and I want it to change what variable to use each run... First time use: $run1 Second time use: $run2 Third time use: $run2 I hope you can understand what I am saying.
'Variable variables'; see http://www.php.net/manual/en/language.variables.variable.php If you meant $run3 on the third time line, then you can use for ($i=1; $i<$SomeNumber; $i++) { $SomeValue = some_function(${run$i}); } Or, use could say for ($i=1; $i<$SomeNumber; $i++) { $VarName = "run$i"; $SomeValue = some_function($$VarName); } If you actually _wanted_ to use '$run2' on the third time, I'm interpreting that to mean you want to limit the maximum value of the digit to 2. If so, you could do for ($i=1; $i<$SomeNumber; $i++) { $VarName = 'run'.max($i, 2); $SomeValue = some_function($$VarName); } -Steve
-------------------------------------------- Brandon Orther WebIntellects Design/Development Manager brandon@webintellects.com 800-994-6364 www.webintellects.com --------------------------------------------
-- +--- "They've got a cherry pie there, that'll kill ya" ------------------+ | Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#36863) next »