Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

How to read dynamic array in to foreach (Smarty 2)

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
masdel1979
Smarty n00b


Joined: 02 Mar 2017
Posts: 2

PostPosted: Thu Mar 02, 2017 4:30 pm    Post subject: How to read dynamic array in to foreach (Smarty 2) Reply with quote

Hi all,
my name is Massimilian and this is my first post..

I want to read dynamically this array (Smarty 2):

test.red_0
test.yellow_0
test.green_0

test.red_1
test.yellow_1
test.green_1

......

test.red_n
test.yellow_n
test.green_n

What is the best way to do?

I tried a different solution, but not work, for example this (i know the number of items, 0 to 29):
Code:

  {section name=count loop=30 start=0 step=1 max=29}
   
    {assign var=test_red value=$test.red_`$smarty.section.count.index`}
    {assign var=test_yellow value=$test.yellow_`$smarty.section.count.index`}
    {assign var=test_green value=$test.green_`$smarty.section.count.index`}
   
    {$test_red}, {$test_yellow}, {$test_green}<br/>
     
  {/section}


and the result is:

Code:
  Array.red_0, Array.yellow_0, Array.green_0
  Array.red_1, Array.yellow_1, Array.green_1
  ....
  Array.red_n, Array.yellow_n, Array.green_n 


Can you help me, please?

Regards Massimiliano
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1642

PostPosted: Thu Mar 02, 2017 5:53 pm    Post subject: Reply with quote

Fix your array and you won't need this retarded construct in first place.
PHP supports multi-dimensional arrays just fine.
Back to top
View user's profile Send private message
masdel1979
Smarty n00b


Joined: 02 Mar 2017
Posts: 2

PostPosted: Fri Mar 03, 2017 8:26 am    Post subject: Reply with quote

AnrDaemon wrote:
Fix your array and you won't need this retarded construct in first place.
PHP supports multi-dimensional arrays just fine.


Hi AnrDaemon,
This is the best solution, but unfortunately it's not possible to fix the Array...

Don't exist any way in Smarty?

Regards Max
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1642

PostPosted: Fri Mar 03, 2017 1:21 pm    Post subject: Reply with quote

Fix. Your. Array.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP