在Wordpress中,我試圖從頭開始創建一個metabox腳本,以便更好地理解Wordpress和PHP。PHP - 對於每個循環問題
雖然我對多維數組上的每個循環都有一些問題。我正在使用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']);
}
我試圖做的是遍歷鍵「頁」陣列中是'meta_box'數組內的數組,同時可以使用'meta_box'數組的鍵值。
我是否需要爲每個循環嵌套一些?
感謝一些指向正確的方向,所以我可以解決這個問題。
你想用這些頁面中的項目做什麼? – Ikke
如果$ meta_box描述了數組,您將獲得$ post_type 0,1並且爲空值$ ['context'],$ value ['priority']。但在你的方式應該是空數組,因爲$ meta_box ['pages']爲空 – Anthony
'以更好地理解Wordpress和PHP.' [咆哮] WordPress的不是最好的代碼[#rans] –