You are imploding and writing config inside for(). It should be better if you do it once after loop.