$model_data - a class that contains 4 properties: code1, .., code4
This code causes an error. Не определено свойство "MyClass.code" :

 for($i = 0; $i++ < 4;){ echo $model_data->code.$i; } 

You can of course rewrite this way:

 for($i = 0; $i++ < 4;){ <? $code='code'.$i?> <? echo $model_data->$code; ?> } 

But still wondering why in the 1st version does not work concatenation?

  • five
    in the first you call the property first, then you glue it, in the second, at first you glue it, then you call it. Option: $model_data->{'code'.$i} - Bookin
  • @Bookin thanks, helped - Jeque

0