Re: Dynamically assigning var namesi

From: Date: Tue, 01 Aug 2006 19:19:01 +0000
Subject: Re: Dynamically assigning var namesi
Groups: php.general 
Request: Send a blank email to php-general+get-239958@lists.php.net to get a copy of this message
Bob Pilly asked earlier today: > Does anyone know if you can assign a new variable name based on the contents of another variable in PHP? If so whats the syntax to do this? $counter = 1; for ($i == 0; $i < 6; $i++) { ${'newVar_' . $counter} = $counter; $counter++; } echo $newVar_1 . "<br />"; echo $newVar_2 . "<br />"; echo $newVar_3 . "<br />"; echo $newVar_4 . "<br />"; echo $newVar_5 . "<br />"; echo $newVar_6 . "<br />"; This displays: 1 2 3 4 5 6 Something like this maybe? David

« previous php.general (#239958) next »