我想输出表格的一个字段,但是字段名称包含来自包围的foreach的变量。
这似乎给出了错误.. 任何解决方案?
<? foreach ($languages as $language): ?>
<? foreach ($accomodations as $accomodation): ?>
<?= $accomodation->about_$language->language ?>
<? endforeach ?>
<? endforeach ?>
答案 0 :(得分:0)
好的,我自己找到了解决方案。
<? foreach ($languages as $language): ?>
<? foreach ($accomodations as $accomodation): ?>
<? $field = 'about_'.$language->language ?>
<?= $accomodation->$field?>
<? endforeach ?>
<? endforeach ?>