Is there a way to tell if you are at last element in the array in a foreach loop?
Or is there an easier way to comma separate values in an array? Obviously the last element doesn't need a comma after it.
Maybe. For example, if you are iterating over a numerically indexed array, you just need to compare the key with the size of the array.
You could consider using [man]implode/man.
implode works perfectly.
<?php $a = array('test', 'test2', 'test3'); $b = implode(', ', $a); echo $b; ?>
Outputs: test, test2, test3