Jump to content

Archived

This topic is now archived and is closed to further replies.

HuggieBear

Create a variable from an array, separated by commas

Recommended Posts

I have the following array:

[code=php:0]$numbers = array(1, 2, 3, 4, 5);
[/code]

Now how do I get this into a variable that looks like this:

[code=php:0]$number_variable = "1, 2, 3, 4, 5";
[/code]

I realise this is the opposite of something like explode() but wondered the easiest way to get it from an array to a variable.

Regards
Huggie

Share this post


Link to post
Share on other sites
The opposite function is simply called implode() :)

So implode(",",$array) will make you a string which will contain all the strings from the array seperated by a comma (,)

http://no2.php.net/implode

Wuhtzu

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.