tags:

views:

38

answers:

2

I'm using a foreach to get membership level information:

  foreach ($aMemLevels as $aMemLevel) { 
     // Add 'mlevels' array to $aForm['inputs'] array
  }

I have a main form variable that hold a large array: $aForm

The form is setup like this:

$aForm = array(
     'form_attrs' => array(
     'name'     => 'menu_access', 
     'action'   => BX_DOL_URL_ROOT.'m/memberships/main_menu',
     'method' => 'post',
     'onsubmit' => 'saveMenuItem(this); return false;'
     ),

    'inputs' => array(
        'mlevels' => array(
            'type' => 'checkbox',
            'caption' => 'Check to enable',
            'name' => '1',  
            'value' => '1',
        ),
    ),
);

I am trying to find a way to add an "mlevels" array to the $aForm['inputs'] array, for each iteration of $aMemLevels.

+2  A: 

You mean like this?

foreach ($aMemLevels as $aMemLevel) { 
     // Add 'mlevels' array to $aForm['inputs'] array
    $aForm['inputs'][]=$aMemLevel;
}
Manos Dilaverakis
+1  A: 

Here an extended example

foreach($aMemLevels as $level){
    $mlevel = array():
    $mlevel['mlevels'] = array(
            'type' => $level['type'],
            'caption' => $level['caption'],
            'name' => $level['name'],  
            'value' => $level['value'],
          );
   $aForm ['inputs'][] = $mlevel; 

}
ITroubs
Thanks this method worked.
whatshakin
if $level looks exactly like i made it in my example you can do it like manos did and just make a $mlevel['mlevels'] = $level;
ITroubs