Jump to content


Photo

Create a variable from an array, separated by commas


  • Please log in to reply
2 replies to this topic

#1 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 04:02 PM

I have the following array:

$numbers = array(1, 2, 3, 4, 5);

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

$number_variable = "1, 2, 3, 4, 5";

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#2 Wuhtzu

Wuhtzu
  • Members
  • PipPipPip
  • Advanced Member
  • 702 posts
  • LocationDenmark -> Fyn -> Aarup

Posted 25 October 2006 - 04:20 PM

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
Feel free to correct me if I'm wrong.

Servage.net: Get 25 Gb of extra storeage by using this coupon code when buying their hosting service - http://www.servage.n...oupon=cust42005

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 05:05 PM

Perfect, I'm loving the logic in that.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users