implode
Go equivalent of PHP’s ‘implode’
In the standard library: strings.Join func Join(a []string, sep string) string http://golang.org/pkg/strings/#Join Cheers!
Alternative of php’s explode/implode-functions in c#
String.Split() will explode, and String.Join() will implode.
PHP Implode But Wrap Each Element In Quotes
Add the quotes into the implode call: (I’m assuming you meant implode) $SQL = ‘DELETE FROM elements WHERE id IN (“‘ . implode(‘”, “‘, $elements) . ‘”)’; This produces: DELETE FROM elements WHERE id IN (“foo”, “bar”, “tar”, “dar”) The best way to prevent against SQL injection is to make sure your elements are properly … Read more
Return single column from a multi-dimensional array [duplicate]
Quite simple: $input = array( array( ‘tag_name’ => ‘google’ ), array( ‘tag_name’ => ‘technology’ ) ); echo implode(‘, ‘, array_map(function ($entry) { return $entry[‘tag_name’]; }, $input)); http://3v4l.org/ltBZ0 and new in php v5.5.0, array_column: echo implode(‘, ‘, array_column($input, ‘tag_name’));
Add a prefix to each item of a PHP array
An elegant way to prefix array values (PHP 5.3+): $prefixed_array = preg_filter(‘/^/’, ‘prefix_’, $array); Additionally, this is more than three times faster than a foreach.
How can I implode an array while skipping empty array items?
You can use array_filter(): If no callback is supplied, all entries of input equal to FALSE (see converting to boolean) will be removed. implode(‘-‘, array_filter($array)); Obviously this will not work if you have 0 (or any other value that evaluates to false) in your array and you want to keep it. But then you can … Read more
How to implode a vector of strings into a string (the elegant way)
Use boost::algorithm::join(..): #include <boost/algorithm/string/join.hpp> … std::string joinedString = boost::algorithm::join(elems, delim); See also this question.