Re: Incrementing a String Name

From: Date: Mon, 23 Apr 2001 00:57:57 +0000
Subject: Re: Incrementing a String Name
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-49776@lists.php.net to get a copy of this message
On Mon, Apr 23, 2001 at 10:58:20AM +1000, Chris Aitken produced this golden nugget: > Hi > > Just a quick puzzle I cant seem to get around at the moment... > > Im trying to create a loop that increments the string name by a digit. For > example, if I had the following 4 strings submitted to a script..... > > $name1 > $name2 > $name3 > $name4 > > What I want to do is create a while loop that will print out the above 4 > strings, incrementing the number part of string automatically. > > while($count<4) { > $count=$count+1; > echo"$increased_string_name\n"; > } > > But I just cant seem to work out how to increment the string name to > display it. > > Any assistance on this would be great. I have a feeling that there is a > better method of attacking this but im only new to PHP and dont know it yet. > There is a better way... Use an array: $name[0] //your $name1 $name[1] // your $name2 etc. and then do while($count<4) { $count=$count+1; echo $name[$count]; } and there you go... that should work just like your code would've in theory... -- andreas landmark / noXtension

« previous php.general (#49776) next »