Removing last comma in PHP?

前端 未结 7 2137
忘掉有多难
忘掉有多难 2020-11-28 16:36

I have this PHP code:

foreach( $wpdb->get_results(
) as $key => $row) {

echo \"[\'\". $row->DATE . \"\',\". $row->total_sales . \"],\";

}
         


        
7条回答
  •  悲&欢浪女
    2020-11-28 17:07

    put your string in substr() function

    $string = "";
    while ($row = mysql_fetch_array($result)) {
      $string .= $name . ', ';
    }
    echo substr($string, 0, strlen($string) - 2);
    

提交回复
热议问题