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

Use FIRST without foreach

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
sarahfoxnz
Smarty Regular


Joined: 11 Apr 2010
Posts: 50

PostPosted: Sat Dec 15, 2018 1:37 am    Post subject: Use FIRST without foreach Reply with quote

Hello.

I have an array

$val > $key
sub-data $number

- main data {$data1}
- main data {$data2}
- main data {$data3}


i have a foreach loop in the template that gets the multiple lines of $val.

each of the $val variables is an array (key).

what i CAN do is do a foreach loop to get the $number, which is also an array. However I do not know what the value (key) of this $number is in advance.

but i DO know there will ONLY be one number for that array. in the sub-array (main data) there are three values i want to extract.

my main question:

I was wondering if I cam do just ONE foreach loop to get the three values, instead of doing 2-3 foreach loops.

For example

TOP foreach loop. example)

:- get 1st value (car)

$car.first.name (get name of car)
$car.first.size (get size of car)
$car.first.color (get color of car)

:- get 2nd value (shoe)

$shoe.first.name (get name of shoe)
$shoe.first.size (get size of shoe)
$shoe.first.color (get color of shoe)


I do not know what the first "key" is in advance,


will this be possible without doing a 2nd foreach loop ? (i dont see the point as there will only be 1 key / sub-array)


i hope that makes sense ?

PS - I did try the above, but i got an error :)
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1530

PostPosted: Mon Dec 17, 2018 7:26 am    Post subject: Reply with quote

Show the actual template code.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    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