Comma separated list from array with “and” before last element

后端 未结 6 1250
青春惊慌失措
青春惊慌失措 2020-12-11 05:43

I have an array ($number_list) that has a dynamically generated list of values. There will be at least 1 value in the array and no more than 4.

Currentl

6条回答
  •  时光取名叫无心
    2020-12-11 06:13

    If the list has at least two elements at the end, you can implode them with " and " (or if your question wasn't borked ", and ") already.

    Then you implode the whole array with ", ".

    • http://php.net/array_splice

    Example:

    Demo: https://eval.in/45277

提交回复
热议问题