How to concatenate variable names in thinkphp5 template files

problem description

there are many rows in the data table, and each row has 10 fields such as day_1, day_2, day_3,..., and day_10. The data has been obtained to the list array and needs to be output as a table in the template file.

the environmental background of the problems and what methods you have tried

use the for loop in volist. You want each line to automatically loop 10 times, automatically typing out $vo.day_1, $vo.day_2, $vo.day_3,... $vo.day_10 each time, but according to the following, {$vo.day_$i} will prompt for an error.

syntax error: unexpected"$i" (T_VARIABLE), expecting","or";"

related codes

{volist name="list" id="vo"}
    {for start="1" end="10"}
        {$vo.day_$i}
    {/for}
{/volist}

what result do you expect? What is the error message actually seen?

excuse me, how can I let the program automatically output the values of $vo.day_1, $vo.day_2, $vo.day_3,... $vo.day_10?

Thank you very much!

May.06,2022

because {$vo.day_$i} will be parsed as , so the syntax is incorrect. According to your requirements, you can change it to the following

{volist name="list" id="vo"}
  {for start="1" end="10"}
    {$vo['day_'.$i]}
  {/for}
{/volist}

1-if you want to traverse a list, volist itself is equivalent to the function of a for loop, so you don't need to write it again

{volist name="list" id="vo"}
    <div>{$vo.day_$i} </div>
{/volist}

2-if you're talking about stitching out all the variables in the array, I suggest you controller write a for loop for stitching and then return to the template page instead of stitching

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e6f55b-46003.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e6f55b-46003.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?