fork download
  1. <?php
  2. $items = array('a', 'b', 'z');
  3.  
  4. function render_array_as_serial_comma($items) {
  5. $final_string = array_pop($items);
  6. if(count($items) >= 1) {
  7. $final_string = implode(', ', $items) . ' and ' . $final_string;
  8. }
  9. return $final_string;
  10. }
  11.  
  12. echo render_array_as_serial_comma($items);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
a, b and z