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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大