Vra

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

Was dit nuttig?

Oplossing

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);

Ander wenke

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.

Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top