Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8535791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:30:59+00:00 2026-06-11T10:30:59+00:00

I have a function that prints out the following into an array like this:

  • 0

I have a function that prints out the following into an array like this:

Array ( [0] => Array ( [id] => 1 [name] => name

However I am unable to foreach through this and I am unsure why?

         <ul>
             {foreach from=$array item=item}
              <li>{$item.name}</li>
            {/foreach}
         </ul>

Update:

{foreach item=topitem from=$getlocations}
         {foreach item=item from=$topitem}
          <option value="{$item.locationid}">{$item.name}</option>
          {/foreach}
      {/foreach}

Function:

function getlocations()
    {
      global $smarty;

      $query = placeholderstackoverflow;

      return $query;

      $smarty->assign('getlocations', $getlocations);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:31:00+00:00Added an answer on June 11, 2026 at 10:31 am

    Your code actually will run through an associative arrays, assuming you’re using Smarty 3.xx.

    Example php code:

    $tpl->assign('yourarray', array( 
      0 => array ( 
          'id' => 1, 
          'name' => 'name'
        )
      )
    );
    

    Example smarty code:

    <ul>
    {foreach from=$yourarray item=item}
        <li>{$item.name}</li>
    {/foreach}
    </ul>
    

    …generates the following HTML output:

    <ul>
        <li>name</li>
    </ul>
    

    If this isn’t your actual or expected result, please add more code.

    Check out,

    • if you’re using a Smarty Version 3.xx and
    • if your array really is properly formed.

    Update:

    Since you’re using Smarty 2.xx, then be advised that foreach has been changed in between.

    For walking through a nested array, you cannot just use one foreach, you have to use more of them. Check out example 7.8 in the manual for version 2.xx.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function that prints the name of all the files in a
I have a terribly uncomplicated test program that prints out the following numbers. i.e.
So I have this JSON struture that I have successfully passed into JS: {
I am using the following function to search through an array recursively: function search2($array,
So I have some function that receives N random 2D points. Is there any
hi i have a function that get information from xml data and print markers
Inside my Controller i have function that runs after user clicks on item, which
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.