The easiest correct solution is to use iterator_to_array
to feed implode
, e.g.
$traversable = /* your iterator, ArrayObject or any other type of Traversable */
echo implode(",", iterator_to_array($traversable));
This will work as expected with anything that can be iterated with foreach
.