There is an object in PHP named $item , and in this object I have properties of
title , title_cn, title_tw
And I would like to create an function that auto generate the properties based on the language, so I coding like this:
<?= $item->title . set_lang(); ?>
And the function:
function set_lang() {
$CI =& get_instance();
$lang = $CI->session->userdata('site_lang');
if ($lang == "english") {
return "";
} else if ($lang == "zh_tw") {
return "_tw";
} else if ($lang == "zh_cn") {
return "_cn";
}
}
However, the name is not generated correctly, it is just the $item->title append with the string of lang code, e.g. my title 1234_tw, titleABC_cn etc...
How to dynamic generate the properties ? Thanks fo helping