Closed Purus closed 2 years ago
Is this not what php's implode()
function is for?
I would think so:
$output = implode(',', $input);
$left = $right = '"';
$output = empty($input) ? '' : $left . implode($left.','.$right, $input).$right;
implode() does not provide the option of adding "right" and "left" characters..
A simple oneliners does the trick, see my example
@WanWizard : I thought this would be a nice an simple to use wrapper for all that.
My 2 cents: I do see the value in adding this function but dislike the implementation. The one @WanWizard provides is cleaner and faster. @Purus if you can update the function implementation with @WanWizard's one and supply tests I'm sure this will fly with the other guys :+1:
Sure. I will update the function..
:thumbsup: for @WanWizard's solution and tests.
@WanWizard last line the delimiter should be $right.','.$left
, shouldn't be?
Eh, yes...
A new function toDelimitedString() to delimit an arry.
Usage: toDelimitedString($array,"'","'",",");
Input = array('a','b','c');
Ouput = 'a','b','c'