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

how t o use a loop in an multidimentional array

 
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
Nilda
Smarty n00b


Joined: 16 Apr 2015
Posts: 1

PostPosted: Thu Apr 16, 2015 5:26 pm    Post subject: how t o use a loop in an multidimentional array Reply with quote

$orders =Array ( [110] => Array ( [name] => Array ( [0] => Canadian Children's Book News Winter 2015 [1] => Canadian Children's Book News Subscription +Best Books for Kids & Teens [2] => Best Books for Kids & Teens: Annual, 2008 ) [product_id] => Array ( [0] => 22 [1] => 14 [2] => 26 ) ) [111] => Array ( [name] => Array ( [0] => Canadian Children's Book News Winter 2015 [1] => Canadian Children's Book News Subscription +Best Books for Kids & Teens [2] => Bookmarks - Hear Our Stories ) [product_id] => Array ( [0] => 22 [1] => 14 [2] => 41 ) ) [112] => Array ( [name] => Array ( [0] => Canadian Children's Book News Winter 2015 [1] => Canadian Children's Book News Subscription +Best Books for Kids & Teens ) [product_id] => Array ( [0] => 22 [1] => 14 ) ) )

$this->assign('orders', $orders);

I used:

{foreach from=$orders item=ord}
{foreach from=$ord item=type}
{foreach from=$type item=cat}
<p>product: {$cat.name}<br />
{/foreach}
{/foreach}
{/foreach}

but doesn't display the name

Thank you
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5063
Location: Hamburg / Germany

PostPosted: Thu Apr 16, 2015 9:35 pm    Post subject: Reply with quote

This should do it

Code:
{foreach from=$orders item=ord}
{foreach from=$ord.name item=name}
<p>product: {$name}<br />   
{/foreach}
{/foreach}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Smarty Development 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