数组1:
$data = array(
'@attributes' => array(
'coolid' => 'V546546',
'emailaddress' => 'member@gmail.com',
));
这是数组2:
$map = array(
'foo' => array(
'id' => 'foo',
'tag' => '{my:foo}',
'label' => __( 'Foo', 'my_plugin' ),
'callback' => 'foo'
));
我正在尝试为$ data ['@ attributes']中的每个键创建一个新数组。我试图让新数组与$ map具有相同的结构,但用$ keys $'['@ attributes']替换'foo'的提及......这样以下输出:
$desiredArray = array(
'coolid' => array(
'id' => 'coolid',
'tag' => '{my:coolid}',
'label' => __( 'coolid', 'my_plugin' ),
'callback' => 'coolid'
));
'emailaddress' => array(
'id' => 'foo',
'tag' => '{my:emailddress}',
'label' => __( 'emailaddress', 'my_plugin' ),
'callback' => 'emailaddress'
));
所有帮助表示赞赏,我已经尝试了这个foreach ..但没有运气
foreach($data['@attributes'] as $key) {
$key = array(
'id' => $key,
'tag' => '{my:'.$key.'}',
'label' => __( $key, 'my_plugin' ),
'callback' => $key
));
}
答案 0 :(得分:0)
$desiredArray = array();
foreach($data['@attributes'] as $key => $value) {
$desiredArray[$key] = array(
'id' => $key,
'tag' => '{my:'.$key.'}',
'label' => __( $key, 'my_plugin' ),
'callback' => $key
);
}