In Wordpress I am trying to produce a metabox script on your own to higher understand both Wordpress and PHP.

I am getting some issues with a for every loop on the multidimensional array though. I am using PHP5.

This is actually 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' => ''
                )
            )
        );

Which is the for every 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 am attempting to do is loop with the secrets within the 'pages' array that is an assortment within the 'meta_box' array and simultaneously have the ability to make use of the key values from the 'meta_box' array.

Should i nest some for every loops?

Would be thankful for some pointers within the right direction in order to solve this.

Maybe it may be nice to produce some class to carry these details.

class Metabox
{
  public $id, $title, $context, $priority, $pages, $fields;

  public function __construct($id, $title, $pages, $fiels, $context='normal', $priority='default')
  {
    $this->id = $id;
    $this->title = $title;
    $this->pages = $pages;
    $this->fields = $fields;
    $this->context = $context;
    $this->priority = $priority;
  }

}

$meta_box = array();

$meta_box[] = new Metabox(
  'monitor-specs', 
  'Monitor Specifications', 
  array('monitors', 'products'),
  array(
    'name' => 'Brand',
    'desc' => 'Enter the brand of the monitor.',
    'id' => $prefix . 'monitor_brand',
    'type' => 'text',
    'std' => ''
  )
);

You can now loop within the meta_box array like:

foreach ($meta_box as $box)
{
  add_meta_box($box->id, $box->title, .. and more)
  // This function could be placed in the metabox object

  /* Say you want to access the pages array : */
  $pages = $box->pages;

  foreach ($pages as $page)
  {
    ..
  }
}

Now you've still got a loop inside a loop, but maybe helps seeing your condition more clearly.

Your foreach begins with $meta_box['pages'], but there's no $meta_box['pages'].

You have a $meta_box[0]['pages'] though, which means you need two loops:

foreach($meta_box as $i => $box)
    foreach($box['pages'] as $page)
        add_meta_box(.., ..); // do whatever

What had you been expecting to stay in your $value variable?

foreach ($meta_box[0]['pages'] as $post_type => $value) {

or

$meta_box = array(...

this here:

$meta_box = array();    
$meta_box[] = array(......

indicates that there's no $meta_box['pages']. meta_box is definitely an array with statistical indexes (look into the [] operator) and every of their elements is definitely an array which has the important thing 'pages'.

so you should utilize foreach on $meta_box, as well as on each element you should utilize the web pages key.. id, title, context are elements on a single level as pages, as you can tell

You're referencing towards the wrong array key

$meta_box[] <-- $meta_box[0]

But, you refer using :-

foreach ($meta_box['pages'] as $post_type => $value) {

Add the array key will solve the issue :-

foreach ($meta_box[0]['pages'] as $post_type => $value) {