Removing last comma in PHP?

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

I have this PHP code:

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

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

}
         


        
7条回答
  •  猫巷女王i
    2020-11-28 16:50

    You'll need variable to store comma state:

    $comma = ""; ## don't need comma before first element
    foreach( $wpdb->get_results(
        ) as $key => $row) {
    
        echo $comma."['". $row->DATE . "',". $row->total_sales . "]";
        $comma = ",";
    }
    

提交回复
热议问题