0

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.

3
  • Are you sure this is working? 'mlevels[$aMemLevel['ID']' should generate a syntax error (note the 'ID' part) Commented Oct 4, 2010 at 15:24
  • No, that's just for the demo I added the note Commented Oct 4, 2010 at 15:25
  • your example code is a little bit incoherent Commented Oct 4, 2010 at 15:26

2 Answers 2

2

You mean like this?

foreach ($aMemLevels as $aMemLevel) { 
     // Add 'mlevels' array to $aForm['inputs'] array
    $aForm['inputs'][]=$aMemLevel;
}
Sign up to request clarification or add additional context in comments.

Comments

1

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; 

}

1 Comment

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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.