[SOLVED] merging two variables for if() structure

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nacho_c
Forum Newbie
Posts: 11
Joined: Tue Sep 14, 2004 2:56 am

merging two variables for if() structure

Post by nacho_c »

How is possible to unite two variables for an if() structure?

for ($i = 1; $i <= 6; $i++)
{
if ($language_$i != ""){
print "bla bla bla";
}

of course this doesn´t work but it is what I mean..
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:arrow: [devnet]metaprogramming[/devnet]

although it's generally better to use arrays for your example...
nacho_c
Forum Newbie
Posts: 11
Joined: Tue Sep 14, 2004 2:56 am

Post by nacho_c »

Ok, but that is for printing..I don´t want to print the variables..
I want to compare them together against some value..

Could you explain how can I merge the values of this variables for this

for ($i = 1; $i <= 6; $i++)
{
if ($language_$i != "")
{
.......
}
}
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read the topics found in my link more closely.
nacho_c
Forum Newbie
Posts: 11
Joined: Tue Sep 14, 2004 2:56 am

Post by nacho_c »

I still don´t get it..maybe I´m stupid but I don´t understand what you exactly mean..

Look, this is what I made and is not working..

for ($i = 1; $i <= 6; $i++)
{
$selected_language = ${'language_$i'};
if ($selected_language != "")
{
}
}

this is not working..please help me :cry:
nacho_c
Forum Newbie
Posts: 11
Joined: Tue Sep 14, 2004 2:56 am

Post by nacho_c »

YESSSSS!!

NOW I GOT IT!

HERE IS THE CODE FOR EVERYBODY!


The language and level variables come from a selection form.
In that form, instead of writing the same code 6 times to make 6 lists
there´s a loop which creates 6 the same lists with different name variable
which is name=\"language_$i\" So with this piece of code I can
process all forms at same time.

for ($i = 1; $i <= 6; $i++)
{
$selected_language = ${'language_'.$i};


if ($selected_language)
{
.....
}

}
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post by dethron »

plz change the topic by adding [SOLVED] string, so we can save time to read :)
Post Reply