need advice on this problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

need advice on this problem

Post 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.
xnex
Forum Newbie
Posts: 3
Joined: Thu Nov 04, 2004 4:58 pm

Post 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;
swdev
Forum Commoner
Posts: 59
Joined: Mon Oct 25, 2004 8:04 am

Post by swdev »

check out the [php_man]implode[/php_man] function in the php manual[/php_man]
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

hi thanks guys...it's working.
Post Reply