title: Can I declare a function inside of the parameter of another function in PHP?
body: <p>I am writing helper functions that allow me to build tables quickly.  I have a function called responsive_table that accepts two parameters:  headings, and rows.  The rows are dynamic and are pulled from a database.  I build an array of rows with a foreach loop because some of the db table rows don't match the contents or order of the html table... some of the cells in the html table contain combinations of db columns, etc. and can't be displayed directly from the db.  None of the rows in my HTML table array are being displayed.  Nothing from inside of the function that's being declared in the function parameter is being displayed.  Here's my code:</p>
  
  <pre><code>&lt;?php
  $output = responsive_table(array('&lt;input type="checkbox" name="all"&gt;', 'Thumbnail', 'Title', 'Location', 'Author', 'Date Submitted', 'Actions'), function(){
      foreach($listing_results as $listing){
          $listings[] = array(
              '&lt;input type="checkbox" name="delete[]" value="'.$listing['listing_id'].'"&gt;',
              '&lt;img src="http://placehold.it/50x50" alt="Thumbnail"&gt;',
              $listing['title'],
              $listing['location'],
              anchor('members/modify/'.$listing['member_id'], $listing['display_name']),
              date($setting['date_format'], $listing['date_submitted']),
              array(
                  array(
                      'title' =&gt; 'Modify Listing',
                      'color' =&gt; 'primary',
                      'href' =&gt; 'listings/modify/'.$listing['listing_id'],
                      'text' =&gt; '&lt;i class="fa fa-pencil"&gt;&lt;/i&gt;'
                  ),
                  array(
                      'title' =&gt; 'Delete Listing',
                      'color' =&gt; 'danger',
                      'href' =&gt; 'listings/delete/'.$listing['listing_id'],
                      'text' =&gt; '&lt;i class="fa fa-eraser"&gt;&lt;/i&gt;',
                      'confirm' =&gt; true
                  )
              )
          );
      }
      return $listings;                       
  });
  
   echo $output;
  
  function responsive_table($headings = array(), $rows = array(), $sortable = false){
  
      $output = '
                                  &lt;div class="table-responsive"&gt;
                                      &lt;table data-sortable class="table"&gt;
                                          &lt;thead&gt;
                                              &lt;tr&gt;
                                                  ';
  
      if(count($headings) &gt; 0){
  
          foreach($headings as $heading){
  
              $output .= '
                                                  &lt;th&gt;'.$heading.'&lt;/th&gt;';
  
          }
  
      }
  
      $output .= '
                                              &lt;/tr&gt;
                                          &lt;/thead&gt;
                                          &lt;tbody&gt;';
  
      if(count($rows) &gt; 0){
  
          foreach($rows as $row){
  
              $output .= '
                                              &lt;tr&gt;
                                                  &lt;td&gt;'.$row.'&lt;/td&gt;
                                              &lt;/tr&gt;';
  
          }
  
      }
  
      $output .= '
                                      &lt;/table&gt;
                                  &lt;/div&gt;';
  
      return $output;
  
  }
  </code></pre>