Forum Moderators: coopster

Message Too Old, No Replies

Parsing a $ POST array into a comma-delimited list

Is there a pre-rolled php function for this?

         

neophyte

1:30 pm on Aug 24, 2007 (gmt 0)

10+ Year Member



Hello All -

if you've got an array that comes from a $_POST like this:

Array ( [apples] => 1 [oranges] => 1 [bananas] => 1 )

is there a way to parse the keys OR values into a comma-delimited list which is then fed into a $var?

Like: $someVar = somefunction($myArray); which, when echoed might look like this: apples,oranges,bananas?

I've looked at functions like extract() but I don't have a need for key names to be transformed into individual $vars - I just need keys or values into a var seperated by commas so that I can explode that $var for another use.

I know I could probably just do a foreach() to get this result, but would just like to know if there's already a php function that would do the job.

Neophyte

justgowithit

1:57 pm on Aug 24, 2007 (gmt 0)

10+ Year Member



Implode [us3.php.net] the array.

whoisgregg

8:20 pm on Aug 24, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the case of getting the $_POST keys, you just add an array_keys [php.net] into your implode:

$post_keys = implode(',', array_keys($_POST));

neophyte

10:46 am on Aug 25, 2007 (gmt 0)

10+ Year Member



justgowithit & whoisgregg -

Thank you both very much for you input; your suggestions worked out perfectly!

Neophyte