Echo a comma on all but the last value? (result from mysql_fetch_array)

后端 未结 11 1983
隐瞒了意图╮
隐瞒了意图╮ 2020-12-21 22:56

How do I echo a comma on all but the last value? Here\'s my code:

while ($servdescarrayrow = mysql_fetch_array($servdescarray)) {

    ECHO $servdescarrayrow         


        
11条回答
  •  南方客
    南方客 (楼主)
    2020-12-21 23:37

    Try using rtrim on your output. For example:

    $output = '';
    
    while ($servdescarrayrow = mysql_fetch_array($servdescarray)) {    
        $output .= $servdescarrayrow['serv_desc'].",";
    }
    
    echo rtrim($output, ',');
    

提交回复
热议问题