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
Post a Comment