我设法动态创建我的数组($$myGenre
包含每个name => id
),但$myGenre
不包含任何东西......我怎样才能使它工作:$myGenre
应该包含每个$$myGenre
,$$myGenre
应该有它的内容name => id
,并且我们应该让每个彼此$myGenre
分开(这里,因为foreach
,我们覆盖 $myGenre
了每种不同的流派):
<?php function findSection() {
global $post, $custom_meta_fields, $myGenre;
foreach ($custom_meta_fields as $fields) {
foreach ($fields as $field) {
if ($field == $fields['genre']) {
$myGenre = array($field['title']);
$$myGenre = array();
} else {
${$myGenre}[$field['name']] = $field['id'];
}
}
var_dump($$myGenre);
}
}
$custom_meta_fields = array(
array( //THRILLER
'genre' => array( 'title' => 'Thriller'),
'fields' => array(
'name' => 'Movie1',
'desc' => 'Desc movie1',
'id' => 'id1',
'type' => 'text'),
array(
'name' => 'Movie2',
'desc' => 'desc movie2',
'id' => 'id2',
'type' => 'text'
),
array(
'name' => 'movie3',
'desc' => 'desc',
'id' => 'id3',
'type' => 'image'
)
),
array(
'genre' => array( 'title' => 'Action'),
'fields' => array('name' => 'Action1',
'desc' => 'desc act1',
'id' => 'idAction1')
)
);
findSection();
谢谢你的帮助