PHP Template Function: last
Posted by Mark [Elevated X Support], Last modified by on 22 April 2015 11:44 AM

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)