Page 1 of 1

need advice on this problem

Posted: Thu Nov 04, 2004 5:59 pm
by mcog_esteban
hello.
let's say i have an array with n elements and i want to create a string
with the elements separated with a comma ",".
if the array is even there's no problem, if is odd there's an extra comma at the end.

what should i do to make this work with any separator?
thanks.

Posted: Thu Nov 04, 2004 6:10 pm
by xnex
if I understand what you're asking, this might be a way to do it

Code: Select all

$f=0;
for($i=0;$i<n;$i++)&#123;
if($f==1)&#123;$str.=", $array&#1111;i]";&#125;
else &#123; $str.=" $array&#1111;i]"; $f=1;&#125;
&#125;

Posted: Thu Nov 04, 2004 6:13 pm
by swdev
check out the [php_man]implode[/php_man] function in the php manual[/php_man]

Posted: Thu Nov 04, 2004 6:18 pm
by mcog_esteban
hi thanks guys...it's working.