Re: printing comma-delimited lists

From: Date: Thu, 04 Oct 2001 14:27:11 +0000
Subject: Re: printing comma-delimited lists
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-69921@lists.php.net to get a copy of this message
> What I'm doing here is fairly obvious (build a comma-delimited >string). > > $arr = array(1,2,3,4,5); > > for ($i=0; $i< sizeof($arr); $i++) { > $lis = $lis . $arr[$i]; > if ($i != (sizeof($arr)-1)) { > $lis = $lis . ','; > } > } > > > Question is, is there a more elegant way? I'm thinking of something > like DTML's sequence-start and sequence-end, in a foreach > construction. > > djo > You could try implode() $lis = implode(",", $arr); -- Stig-Ørjan Smelror Systemutvikler Linux Communications AS Sandakerveien 48b Box 1801 - Vika N-0123 Oslo, Norway tel. +47 22 09 28 80 fax. +47 22 09 28 81 http://www.lincom.no/

« previous php.general (#69921) next »