-3

hi everyone i have problem. i have the code like this

$foo = array(':1:',':2:',':3:4:');

and I want the result is like this

$foo = array('1','2','3,4');

thank's before for help :) sorry for my english

1

2 Answers 2

0

array_map() with a callback using trim() and str_replace() will do the trick:

$foo = array_map(function($val) {
    $val = trim($val, ':');
    return str_replace(':', ',', $val);
}, $foo);
1
  • You beat me by 18 seconds, congratulations :) May 14, 2014 at 7:15
0

Use the array_map() function to traverse and modify an array:

$foo = array_map(function($v) {
    return str_replace(':', ',', trim($v, ':'));
}, $foo);

I'm assuming you want to trim off leading and trailing colons and convert the others to commas. Your question isn't very clear in describing requirements.

Not the answer you're looking for? Browse other questions tagged or ask your own question.