Replace the last comma with an & sign

后端 未结 8 1372
小鲜肉
小鲜肉 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 00:08

    $bedroom_list = implode(", ", array_filter($bedroom_array));
    
    $vars =  $bedroom_list;
    
    $last = strrchr($vars,",");
    
    $last_ = str_replace(",","&",$last);
    
    echo str_replace("$last","$last_",$vars);
    

提交回复
热议问题