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

后端 未结 6 1253
青春惊慌失措
青春惊慌失措 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:11

    # pop the last element off the array and formate text
    if( count( $number_list )>1 ){
        $and = " and ".array_pop( $number_list );
    }else{
        $and = '';
    }
    # Implode number list , and  append $and
    $comma_list = implode(', ', $number_list).$and;
    

提交回复
热议问题