如何使用数组映射修改以下数组。到目前为止,我无法达到想要的结果所以这是我的问题:
转换它:
Array
(
[Open+Sans:300,300italic,regular,italic,600,600italic,700,700italic,800,800italic] => Open Sans
[Roboto:100,100italic,300,300italic,regular,italic,500,500italic,700,700italic,900,900italic] => Roboto
[Oswald:300,regular,700] => Oswald
)
进入
Array
(
array('label' => 'Open Sans','value' => 'Open+Sans:300,300italic,regular,italic,600,600italic,700,700italic,800,800italic'),
array('label' => 'Roboto','value' => 'Roboto:100,100italic,300,300italic,regular,italic,500,500italic,700,700italic,900,900italic'),
array('label' => 'Oswald','value' => 'Oswald:300,regular,700'),
);
答案 0 :(得分:3)
$data = array(
'foo' => 'bar',
'baz' => 'bla',
);
$result = array_map(
function($key, $value) {
return array(
'label' => $key,
'value' => $value,
);
},
array_keys($data),
array_values($data)
);
var_dump($result);