How to remove the last comma of array? currently the result is "apple,orange,papaya,"
i wan the result is "apple,orange,papaya"
for($i = 0; $i < $count; $i++) {
$message.= " ".$Cbox[$i].", ";}
How to remove the last comma of array? currently the result is "apple,orange,papaya,"
i wan the result is "apple,orange,papaya"
for($i = 0; $i < $count; $i++) {
$message.= " ".$Cbox[$i].", ";}
You can use rtrim()
for this.
$trimmed_message = rtrim($message, ",");
A possible alternative would be to add each item to an array, and then implode()
it afterwards. For example,
$message_items = [];
for($i = 0; $i < $count; $i++) {
$message_items[] = $Cbox[$i];
}
$message = implode(", ", $message_items);
use
join()
function
$message = join(",",$Cbox);
or use
implode()
function
$message = implode(",",$Cbox);
U can use rtrim()
and remove the last , from the string
Ex : rtrim($message,', ');