Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - remove comma from the last loop

Tags:

php

while-loop

I have a PHP while LOOP, and I want to remove last comma , from echo '],'; if it is last loop

            while($ltr = mysql_fetch_array($lt)){
                echo '[';
                echo $ltr['days']. ' ,'. $ltr['name'];
                echo '],';
            }
like image 755
user007 Avatar asked May 31 '26 05:05

user007


1 Answers

Create an array with the elements as you go along so that they look like array = ([ELEMENT INFO], [ELEMENT INFO], [ELEMENT INFO]) and then implode the array with a comma.

like image 113
Eric Hotinger Avatar answered Jun 01 '26 21:06

Eric Hotinger