Welcome Guest, Not a member yet? Register   Sign In
use variable in a construct sintax?
#1

[eluser]chefnelone[/eluser]
Hello
I need to use a variable in this sintax:

Code:
echo $photos->title;?>

Something like:
Code:
$_SESSION['lang_txt'] = '_en';
// THEN I NEED: $photos->title_en;

// TRIED WITH:
echo $photos->title.$_SESSION['lang_txt'];
//BUT...NOT WORKING


// IT DOES THE JOB WITH THIS:
$title_lang = 'title'.$_SESSION['lang_txt'];
echo $photos->$title_lang;

//BUT I'M LOOKING TO DO IT IN ONE SINGLE LINE...

thanks
#2

[eluser]WanWizard[/eluser]
Assuming the object property title_en exists, you can use
Code:
echo $photos->{'title'.$_SESSION['lang_txt']};
#3

[eluser]chefnelone[/eluser]
[quote author="WanWizard" date="1284391155"]Assuming the object property title_en exists, you can use
Code:
echo $photos->{'title'.$_SESSION['lang_txt']};
[/quote]

Thanks wan




Theme © iAndrew 2016 - Forum software by © MyBB