RPeraltaJr
5/23/2017 - 4:24 PM

Comma Separator ForEach Loop Except Last

Comma Separator ForEach Loop Except Last

<?php
  $arr = array(1,2,3,4,5,6,7);
  $copy = $arr;
  foreach ($arr as $val) {
      echo $val;
      if (next($copy )) {
          echo ','; // Add comma for all elements instead of last
      }
  }
?>