use*_*150 0 php arrays multidimensional-array
我有一个像这样多维的数组
array(
0 => array(
'User' => array(
'email' => 'test@yahoo.com ,testuser@yahoo.com',
'username' => 'test,testuser',
'description' => 'description1,description2'
)
)
);
Run Code Online (Sandbox Code Playgroud)
我想将此数组转换为此表单
$User = array(
'email' => array(
'test@yahoo.com',
'testuser@yahoo.com'
),
'username' => array(
'test',
'testuser'
),
'description' => array(
'description1',
'description2'
)
);
Run Code Online (Sandbox Code Playgroud)
请帮忙!!!
仅适用于一个指数:
$arrayTwoD = array();
foreach ($valueMult[0]['User'] as $key => $value) {
$arrayTwoD[$key] = array_push(explode(',', $value));
}
Run Code Online (Sandbox Code Playgroud)
如果您有多个索引$multArray:
$arrayTwoD = array();
foreach ($multArray as $keyMult => $valueMult) {
foreach ($valueMult['User'] as $key => $value) {
$arrayTwoD[$keyMult][$key] = array_push(explode(',', $value));
}
}
Run Code Online (Sandbox Code Playgroud)
要么
$arrayTwoD = array();
foreach ($multArray as $array) {
foreach ($array['User'] as $key => $value) {
$arrayTwoD[$key] = array_push(explode(',', $value));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
876 次 |
| 最近记录: |