Вопрос

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