Bhanu Prakash Pandey Bhanu Prakash Pandey - 4 months ago 76
PHP Question

How to find last index of foreach loop in smarty

How to get last index value of foreach loop in smarty,i m new for smarty I have used this code but its not working

{foreach from=$cityList key=myId item=i name=foo}
{$i.location_name}{if $}<hr>{else}-{/if}

i want that when their is last city name after this its come horizontal line otherwise its like india-USA-Japan- but at last it come Japan-china

In .php i use

$main_smarty = new Smarty;

query to find citylist


You're looking for this one:

{foreach from=$cityList key=myId item=i name=foo}
    {if $}
        <p>This is the last item from the array!</p>

As you see, the property you need to check is $ where foo is the name of your object.