Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put all indexs of array in a comma separated string [closed]

I have an array that looks like this:

array('first' => 'value1', 'second' => 'value2', ...);

How can I get all the keys and put them in a comma separated string?

At the very end I need something like this, to do a query:

values IN ('first','second',...)

Thanks

like image 812
Hommer Smith Avatar asked Jan 17 '13 13:01

Hommer Smith


People also ask

How to convert array data into comma separated string?

To convert an array to a comma-separated string, call the join() method on the array, passing it a string containing a comma as a parameter. The join method returns a string containing all array elements joined by the provided separator. Copied!

How do you display array values separated by commas?

The comma separated list can be created by using implode() function. The implode() is a builtin function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function.

How to get comma separated values in c#?

Use the string join() function to get the comma separated strings.

How do you convert a list to a comma separated string in python?

How to Convert a Python List into a Comma-Separated String? You can use the . join string method to convert a list into a string. So again, the syntax is [seperator].


1 Answers

should be enough:

echo "'".implode("','", array_keys($array))."'";
like image 140
Rufinus Avatar answered Sep 28 '22 22:09

Rufinus