fuel / helpers

FuelPHP Framework - Generic helpers library
MIT License
17 stars 7 forks source link

Update Arr.php #2

Closed Purus closed 2 years ago

Purus commented 10 years ago

A new function toDelimitedString() to delimit an arry.

Usage: toDelimitedString($array,"'","'",",");

Input = array('a','b','c');

Ouput = 'a','b','c'

emlynwest commented 10 years ago

Is this not what php's implode() function is for?

WanWizard commented 10 years ago

I would think so:

$output  = implode(',', $input);

$left = $right = '"';
$output  = empty($input) ? '' : $left . implode($left.','.$right, $input).$right;
Purus commented 10 years ago

implode() does not provide the option of adding "right" and "left" characters..

WanWizard commented 10 years ago

A simple oneliners does the trick, see my example

Purus commented 10 years ago

@WanWizard : I thought this would be a nice an simple to use wrapper for all that.

frankdejonge commented 10 years ago

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:

Purus commented 10 years ago

Sure. I will update the function..

emlynwest commented 10 years ago

:thumbsup: for @WanWizard's solution and tests.

sagikazarmark commented 10 years ago

@WanWizard last line the delimiter should be $right.','.$left, shouldn't be?

WanWizard commented 10 years ago

Eh, yes...