How to remove comma at the end of an array?
Need output: 1,2,3,4,5 and not 1,2,3,4, 5,
I know I can use implode, but is there another way?
$massive = [1, 2, 3, 4, 5];
foreach($massive as $items){
echo $items. ', ';
}
>Solution :
You can use implode and if don’t want to use the inbuilt function then use a new variable like this
<?php
$massive = [1, 2, 3, 4, 5];
$str="";
foreach($massive as $items){
$str .= $items.",";
}
echo substr($str,0,-1)
?>