Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Whats the PHP equivalent of $string${otherstring} ??

Status
Not open for further replies.

JohnnyT

Programmer
Jul 18, 2001
167
0
0
GB
I'm trying to run through a loop to check variables that are sequentially numbered (ie, $year1, $year2, $year3 etc etc).

I want to be able to loop a count in order to check these variables.

while($count < 99) {
$result = $year${count};
$count++;
}

The above would be workable in Perl but I don't know how to do the equivalent in PHP.

Thanks for your help

Cheers

JT I don't make mistakes, I'm merely beta-testing life.
 
try something like:
while ($count < 99)
{
$varName = 'year' . $count;
$result = $GLOBALS[&quot;varName&quot;];
$count++;
}
or:
while ($count < 99)
{
$varName = 'year' . $count;
$result = ${$varName};
$count++;
}

Please correct me if I'm wrong...

-Cursed
 
Lalli

Haven't tried the first one but the second one works an absolute treat !!

A big big thanks!

Cheers

JT I don't make mistakes, I'm merely beta-testing life.
 
Why would you want to do this though? Using arrays makes things a lot easier and is generally the way most people use. //Daniel
 
Daniel

Its for an Admin section to a script that puts up a link to a cartoon on a webpage dependant on the date.

The admin page checks how many cartoons are in the directory, then produces a table with the 'episode' number and the date for each one. As its all one form, the names for the form variables are called day1, month1, year1, then day2, month2, year2, etc etc for the number of episodes it has found in the folder.

I can then change the day, month and year that each episode will be shown and submit the form. The script then parses through $day1 -- $day99 or whatever and the same with the month and year and puts them into the database.

The script that the user sees, basically just checks the date and the dates that the episodes are due to be shown and all the episode dates that preceed todays date are linked. So the user can view them.

The whole idea of the script is to display a new link to a cartoon every two weeks or so on a page.

There's probably a really really easy way of doing this but I'm a self-taught programmer (and not a very good one at that) so I just muddle on...

Cheers

JT ;-)) I don't make mistakes, I'm merely beta-testing life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top