fork download
  1. <?php
  2.  
  3. $credits = array('foo', 'bar', 'baz');
  4. switch (count($credits)) {
  5. case 0:
  6. $result = '';
  7. break;
  8. case 1:
  9. $result = reset($credits);
  10. break;
  11. default:
  12. $last = array_pop($credits); // warning: this modifies the array!
  13. $result = implode(', ', $credits).' & '.$last;
  14. break;
  15. }
  16.  
  17. echo $result;
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
foo, bar & baz