在 Wordpress 中,我试图从头开始创建一个元框脚本,以更好地理解 Wordpress 和 PHP。
不过,我在多维数组上的 for each 循环中遇到了一些问题。我正在使用 PHP5。
这是数组:
$meta_box = array();
$meta_box[] = array(
'id' => 'monitor-specs',
'title' => 'Monitor Specifications',
'context' => 'normal',
'priority' => 'default',
'pages' => array('monitors', 'products'),
'fields' => array(
array(
'name' => 'Brand',
'desc' => 'Enter the brand of the monitor.',
'id' => $prefix . 'monitor_brand',
'type' => 'text',
'std' => ''
)
)
);
这是每个循环:
foreach ($meta_box['pages'] as $post_type => $value) {
add_meta_box($value['id'], $value['title'], 'je_format_metabox', $post_type, $value['context'], $value['priority']);
}
我要做的是循环遍历“pages”数组中的键,该数组是“meta_box”数组中的一个数组,同时能够使用“meta_box”数组的键值。
我需要为每个循环嵌套一些吗?
将不胜感激一些正确方向的指示,以便我可以解决这个问题。