remove last character after concatenating string output by for loop?

后端 未结 3 1792
迷失自我
迷失自我 2021-01-17 03:28
$holder = \'\';

foreach($fields as $key){
    $holder .= $key.\', \';
}

echo $holder;

I have the code above, it outputs \"a, b, c, \" I want to r

3条回答
  •  Happy的楠姐
    2021-01-17 03:30

    You can use substr like this

    $holder = '';
    
    foreach($fields as $key){
        $holder .= $key.', ';
    }
    $newholder=substr($holder, 0, -1); 
    echo $newholder;
    

提交回复
热议问题