How to append object name with variable string in php? -


i have array of objects this

$names=array ( [0] => stdclass object ( [id] => 1                                          [heading_de] => title_deutch                                          [heading_en] => title_english ); 

and have var

$lang="_en"; 

when want try this

foreach ($names $title)         {           $title = $title->heading.$lang;         } 

i got

$title="_en" 

but when try this

foreach ($names $title)         {           $title = $title->heading_en;         } 

i got ok, mistake, hot combine string , object ?

you want use variable variables in php, try following

  $lang = "_en";   foreach ($names $title) {     echo $title->{'heading' . $lang};   } 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -