dongxiaoyan4388 2011-12-07 12:11
浏览 38
已采纳

PHP - 针对每个循环问题

In Wordpress I'm trying to create a metabox script from scratch to better understand both Wordpress and PHP.

I'm having some problems with a for each loop on a multidimensional array though. I'm using PHP5.

This is the array:

$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' => ''
                )
            )
        );

And this is the for each loop:

foreach ($meta_box['pages'] as $post_type => $value) {
            add_meta_box($value['id'], $value['title'], 'je_format_metabox', $post_type, $value['context'], $value['priority']);
        }

What I'm trying to do is loop through the keys in the 'pages' array which is an array inside the 'meta_box' array and at the same time be able to use the key values of the 'meta_box' array.

Do I need to nest some for each loops?

Would be grateful for some pointers in the right direction so I can solve this.

  • 写回答

5条回答 默认 最新

  • drnx3715 2011-12-07 12:16
    关注
    foreach ($meta_box[0]['pages'] as $post_type => $value) {
    

    or

    $meta_box = array(...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥20 SQL server表计算问题
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)