0

I have a list like:

$myList = "1,2,3,4,5,6,7,8,9"

I want my list to be displayed as

1,2,3
4,5,6
7,8,9

How do I achieve that?

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55

2 Answers2

1

you can use explode() to brack list to array and print it as you wish

$myList = "1,2,3,4,5,6,7,8,9";
$myList_explode = explode(",",$myList);
for($i=0;$i<sizeof($myList_explode);$i++){
 echo $myList_explode[$i];
 if(($i+1)%3==0){
  echo "</br>";
 }else{
   echo ",";
 }
}
-1

It depends what you mean by "displayed", but if you want to echo it to the screen, literally just echo that string to the page and you should get that result (unless the no comma in between 3 and 4 and 6 and 7 is intentional), if not just echo $mylist