title: foreach within a class PHP
body: <p>I am new to OOP and have a class, inside this class I am trying to run </p>
  
  <pre><code>foreach($categories as $category) { 
                  public function beam_channels_setting.$category-&gt;name()
                  {
                      echo "&lt;input name='beam_plugin_options[beam_channels".$category-&gt;name"]' type='text' value='{$this-&gt;options['beam_channels.$category-&gt;name']}'/&gt;";
  
                          } 
          }
  </code></pre>
  
  <p>However I keep getting this error: unexpected T_FOREACH</p>
  
  <p>I understand that this is because it is looking for a function, but I do not know how to overcome this, would I put it all within another function?</p>
  
  <h2>class</h2>
  
  <pre><code>Class BEAM_Options {
  
      public $options;
      public $categorielist;
  
      public function __construct()
      {
          $args = array(
              'type'                     =&gt; 'post',
              'orderby'                  =&gt; 'name',
              'order'                    =&gt; 'ASC',
              'hide_empty'               =&gt; 0, //&lt;--IMPORTANT!!
              'hierarchical'             =&gt; 1,
              'taxonomy'                 =&gt; 'category',
              'pad_counts'               =&gt; false );
          $categories = get_categories($args);
          $this-&gt;options = get_option('beam_plugin_options');
          $this-&gt;register_settings_and_fields();
      }
  
      public function add_menu_page()
      {
          add_options_page('Ad Management', 'Ad Management', 'administrator', __FILE__, array('BEAM_Options', 'display_options_page'));
      }
  
      public function display_options_page()
      {
          ?&gt;
  
          &lt;div class="wrap"&gt;
              &lt;?php screen_icon(); ?&gt;
              &lt;h2&gt; Ad Management&lt;/h2&gt;
              &lt;form method="post" action="options.php"&gt;
                  &lt;?php settings_fields('beam_plugin_options'); ?&gt;
                  &lt;?php do_settings_sections(__FILE__); ?&gt;
  
  
                  &lt;p class="submit"&gt;
                      &lt;input name="submit" type="submit" class="button-primary" value="Save Changes" /&gt;
                  &lt;/p&gt;
              &lt;/form&gt;
          &lt;/div&gt;
          &lt;?php
      }
  
      public function register_settings_and_fields()
      {
          register_setting('beam_plugin_options', 'beam_plugin_options');
          add_settings_section('beam_main_section', 'Settings', array($this, 'beam_main_section_cb'), __FILE__); //id, title, section, callback, page
          add_settings_field('beam_refresh_time_truth','Do you want the Advertisements to Auto-Refresh?', array($this,'beam_refresh_time_truth_setting'), __FILE__, 'beam_main_section');
          add_settings_field('beam_refresh_time','Refresh Time(seconds)', array($this,'beam_refresh_time_setting'), __FILE__, 'beam_main_section');
          $args = array(
              'type'                     =&gt; 'post',
              'orderby'                  =&gt; 'name',
              'order'                    =&gt; 'ASC',
              'hide_empty'               =&gt; 0, //&lt;--IMPORTANT!!
              'hierarchical'             =&gt; 1,
              'taxonomy'                 =&gt; 'category',
              'pad_counts'               =&gt; false );
              $categories = get_categories($args);
            foreach($categories as $category) { 
          add_settings_field("beam_channels.$category-&gt;name","$category-&gt;name", array($this,"beam_channels_setting.$category-&gt;name"), __FILE__, 'beam_main_section');
          }
      }
  
  
            foreach($categories as $category) { 
                  public function beam_channels_setting.$category-&gt;name()
                  {
                      echo "&lt;input name='beam_plugin_options[beam_channels".$category-&gt;name"]' type='text' value='{$this-&gt;options['beam_channels.$category-&gt;name']}'/&gt;";
  
                          } 
          }
  }
  </code></pre>