Home » Php » php – Smarty: print a specific element of an array WITHOUT using foreach loop

php – Smarty: print a specific element of an array WITHOUT using foreach loop

Posted by: admin July 12, 2020 Leave a comment

Questions:
{foreach from=$myArray item=item}
    {$item.attribute}
{/foreach}

instead of printing all attributes of each element of the array, I want to output only the 3rd element WITHOUT using a foreach loop, is it possible?

I’m looking for something like the below, but I don’t know the syntax:

$myArray[2].attribute
How to&Answers:

{$myArray[2].attribute} would be correct. Did you try it?

Answer:

Use {$myArray.2.attribute} to get the attribute.

Answer:

$myArray[2]->attribute this one works for me.