Replace the last comma with an & sign

后端 未结 8 1373
小鲜肉
小鲜肉 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:47

    Pop off the last element, implode the rest together then stick the last one back on.

    $bedroom_array = array('studio', 'one_bed', 'two_bed', 'three_bed', 'four_bed');
    $last = array_pop($bedroom_array);
    $string = count($bedroom_array) ? implode(", ", $bedroom_array) . " & " . $last : $last;
    

    Convert & to the entity & if necessary.

提交回复
热议问题