1

I am having one array like this. The tree structure of this array is very big. I want to print the array using the smarty tags in the html file. I am using this code to do this,

Assigned like this in PHP file, $smarty->assign("arrForumData", $arrForumData);

In HTML File like this for single dimension array.

{foreach item=foo from=$arrForumData}
{$foo.question}
{$foo.name} etc...
{/foreach}

I dont know how to print array which is like below in smarty. Please guide me how to print multidimension array's in smarty. Hope my question is clear. thanks in advance.

ARRAY

1
  • Please provide an example of what you would like accomplished. It's not clear whether you want to print the whole array structure, or just the entries containing a name and question Commented Dec 27, 2012 at 14:28

2 Answers 2

2

Exact answer. Working perfect for me.

{foreach name=outer item=v from=$arrForumData}
        {$v[0].question_id}
        {$v[0].project_id}
        {$v[0].name}
        {$v[0].email}
        {$v[0].question}
        {$v[0].created_on}

      {foreach key=key item=item from=$v[1]}
        {$item.aQId}
        {$item.aAns}
        {$item.aName}
        {$item.aEmail}
        {$item.aDate}
      {/foreach}
{/foreach}
Sign up to request clarification or add additional context in comments.

Comments

1

You can try something like this:

{foreach key=key item=item from=$arrForumData}
  {if $item|@is_array}
    {foreach key=inner_key item=inner_item from=$arrForumData[$key]}
      {if $inner_item|@is_array}
        {foreach key=innermost_key item=innermost_item from=$arrForumData[$key][$inner_key]}
            {$innermost_item.aQId}
            {$innermost_item.aAns}
            {$innermost_item.aName}
            {$innermost_item.aEmail}
            {$innermost_item.aDate}
        {/foreach}
      {else}
        {$inner_item.question_id}
        {$inner_item.project_id}
        {$inner_item.name}
        {$inner_item.email}
        {$inner_item.question}
        {$inner_item.created_on}
      {/if} 
    {/foreach}
 {/if}
{/foreach}

1 Comment

Why not? Do you need someone to give you a complete written solution to your problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.