Build comma separated string in PHP Loop

后端 未结 4 652
抹茶落季
抹茶落季 2021-01-21 22:36

Hello Guys i need to do this,

I have a common loop

foreach ($stuffs as $stuff) {
echo $stuff;
}

Lets assume $stuff is an \'id\' of a my

4条回答
  •  星月不相逢
    2021-01-21 23:06

    implode should be the tool:

    implode(",", $stuffs);
    

    will return a comma separated list.

    Test

    $myarray=array(1,2,"hello",4,5);
    echo implode(",", $myarray);
    

    returns

    1,2,hello,4,5
    

提交回复
热议问题