Replace the last comma with an & sign

后端 未结 8 1352
小鲜肉
小鲜肉 2020-12-09 23:21

I have searched everywhere but can\'t find a solution that works for me.

I have the following:

$bedroom_array = array($studio, $one_bed, $two_bed, $t         


        
8条回答
  •  遥遥无期
    2020-12-09 23:49

    A one-liner alternative, that will work for any size array ($b = $bedroom_array):

    echo count($b) <= 1 ? reset($b) : join(', ', array_slice($b, 0, -1)) . " & " . end($b); 
    

提交回复
热议问题