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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -