Uncategorized

Processing multidimensional array with smarty


Array ( 
    [category] => Array ( 
			[0] => Array ( 
					[id] => 72 
					[cat_name] => Nature Wool 
					[sub_cats] => Array ( 
							     [0] => Array ( 
										[sub_cat] => Blue Natural wool 
										[sub_cat_id] => 154 
										[cat_id] => 72 
									) 
							    [1] => Array ( 
								           [sub_cat] => Red Natural 
								           [sub_cat_id] => 155 
									   [cat_id] => 72 
									) 
							) 
					) 
			[1] => Array ( 
					[id] => 73 
					[cat_name] => Handmand Paper 
					[sub_cats] => Array ( 
								[0] => Array ( 
								                [sub_cat] => Blue Handmade 
								                [sub_cat_id] => 152
								                [cat_id] => 73 
								              ) 
								[1] => Array ( 
										[sub_cat] => Green 
										[sub_cat_id] => 149 
										[cat_id] => 73 
									     ) 
								[2] => Array ( 
										[sub_cat] => Red Handmade 
										[sub_cat_id] => 153 
										[cat_id] => 73 
									     ) 
							) 
											) 
			[2] => Array ( 
					[id] => 76 
					[cat_name] => Beautiful Papers 
					[sub_cats] => Array ( 
								[0] => Array ( 
								             [sub_cat] => Blue 
								             [sub_cat_id] => 150 
								             [cat_id] => 76 
									) 
								[1] => Array ( 
										[sub_cat] => Red 
										[sub_cat_id] => 151 
										[cat_id] => 76 
										) 
							) 
					) 
			) 
	)
============= Smarty code to process the above array ======================
	{foreach from = $all_cats item = val_00 name = foo key = key}
 
    	    {foreach from = $val_00 item = val_01 name = fooo key = keys}
        		{$val_01.cat_name}<br />
                
                {foreach from = $val_01.sub_cats item = val_02 name = foooo key = keyss}
               		 {$val_02.sub_cat}<br />
                     
                {/foreach}<br />
           {/foreach}
      {/foreach}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s