Answer the question
In order to leave comments, you need to log in
How can you convert the value of an array element to an array?
I have an array like this:
Array
(
["Московская обл."] => "1 Мая","1 Поселок","2-я Смирновка","3-й Участок","4-й Участок","52127 городок",
["Удмуртская респ."] => "Якшур-Бодья",
)
Array
(
["Московская обл."] =>
Array (
"1 Мая",
"1 Поселок",
"2-я Смирновка",
"3-й Участок",
"4-й Участок",
"52127 городок"
),
["Удмуртская респ."] =>
Array (
"Якшур-Бодья"
)
)
Answer the question
In order to leave comments, you need to log in
$input = [
'foo' => 'one, two, three',
'bar' => 'baz',
];
$result = array_map(
function ($value) {
return array_map('trim', explode(',', $value));
},
$input
);
var_dump($result);
array(2) {
["foo"]=>
array(3) {
[0]=>
string(3) "one"
[1]=>
string(3) "two"
[2]=>
string(5) "three"
}
["bar"]=>
array(1) {
[0]=>
string(3) "baz"
}
}
$your = [];
$ret = array_map(function ($in) {return explode(',', $in);}, $your);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question