Build comma separated string in PHP Loop

后端 未结 4 753
抹茶落季
抹茶落季 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 22:57

    This worked in my case (detects if isn't the loop last iteration):

    foreach($array as $key => $val){
        ...
        if($key!==count($array)-1){echo ',';}
    }
    

提交回复
热议问题