array results into comma seperated?

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
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

array results into comma seperated?

Post by ianhull »

Hi Guys,

I would like to list the values of an array like this.

Code: Select all


$a = array("me", "and", "mydog");

//me, and, mydog

please help.

Thanks
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

nevermind :)

foreach
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I think implode() would be a better choice for this
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Still stuck

Code: Select all



   foreach ($varName as $varNames) {
   $varNames = $varNames.", ";
   }



how do i get this out of what I have here?

"me, and, mydog"

notice I need to remove the last comma

thanks
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

Hey thanks :)

implode();
Post Reply