How to concatenate PHP variable name?

后端 未结 4 2066
抹茶落季
抹茶落季 2020-11-27 05:26

I have a PHP for loop:

for ($counter=0,$counter<=67,$counter++){

echo $counter;
$check=\"some value\";

}

What I am trying to achieve i

4条回答
  •  死守一世寂寞
    2020-11-27 06:02

    This is usable in some cases. For example if your app has something like 2 language entries in DB.

    echo $this->{'article_title_'.$language};
    

    That's much more usable than for example this;

    if($language == 'mylanguage1')
        echo $this->article_title_mylanguage1;
    else
        echo $this->article_title_mylanguage2;
    

    Obviously this is what you should not have to do in your multilingual app, but i have seen cases like this.

提交回复
热议问题