How can a foreach loop be properly implemented in a Smarty template in PHP?

To properly implement a foreach loop in a Smarty template in PHP, you can use the {foreach} Smarty tag along with the {foreachelse} tag to handle empty arrays. Within the {foreach} tag, you can access the array elements using the $smarty.foreach loop variable.

{foreach $array as $item}
    {$item}
{/foreach}

{foreachelse}
    No items found
{/foreach}