December 08, 2021
Useful to add custom styles or punctuation to last item in an array.
$lastElement = array_key_last($subjects);
$count = 0;
foreach($subjects as $sub) {
if($count == $lastElement) {
echo $sub->name;
} else {
echo $sub->name .', ';
}
$count++;
} ?></li>