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

后端 未结 11 1987
隐瞒了意图╮
隐瞒了意图╮ 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:44

    you can remove the last comma after generating the string like so:

    $str = '';
    while ($servdescarrayrow = mysql_fetch_array($servdescarray)) {
       $str .= $servdescarrayrow['serv_desc'].",";
    }
    $str = substr($str, 0, strlen($str) - 1);
    echo $str;
    

提交回复
热议问题