PHP Template Function: last
Posted by Mark [Elevated X Support], Last modified by kayako kayako on 19 January 2017 11:04 PM

Description:

Returns either true or false based on whether or not a key in an array is the last element.

Common Location:

/cms_admin/phptemplate/<templatefolder>/functions/standard.tpl

Usage:

<?php
  $names = ["Anne", "Beth", "Carol", "Denise"];

  foreach($names as $key => $name)
  {
    echo $name;
    if (!last($sets, $key)) echo ", ";
  }

?>

In this case, a comma will be printed after each name, unless the element is the last name.

Arguments

1) The full array

2) The key of the array.

Output

Anne, Beth, Carol, Denise

(0 vote(s))
Helpful
Not helpful

Comments (0)