Displaying the last element of an OpenCart 2x array

To display the last element of any array in a tpl file, you can use this construction, suggested by one very good person

<?php $i = 1; ?>
<?php foreach( $linked_categories as $linked_category ){ ?>
   <?php if (count($linked_categories) == $i) { ?>
     <a href="<?php echo $linked_category['href']; ?>"><?php echo $linked_category['name']; ?></a>
     <?php } ?>
     <?php $i++; ?>
<?php } ?>

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.