문제

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

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top