Can I declare a function inside of the parameter of another function in PHP? -


i writing helper functions allow me build tables quickly. have function called responsive_table accepts 2 parameters: headings, , rows. rows dynamic , pulled database. build array of rows foreach loop because of db table rows don't match contents or order of html table... of cells in html table contain combinations of db columns, etc. , can't displayed directly db. none of rows in html table array being displayed. nothing inside of function that's being declared in function parameter being displayed. here's code:

<?php $output = responsive_table(array('<input type="checkbox" name="all">', 'thumbnail', 'title', 'location', 'author', 'date submitted', 'actions'), function(){     foreach($listing_results $listing){         $listings[] = array(             '<input type="checkbox" name="delete[]" value="'.$listing['listing_id'].'">',             '<img src="http://placehold.it/50x50" alt="thumbnail">',             $listing['title'],             $listing['location'],             anchor('members/modify/'.$listing['member_id'], $listing['display_name']),             date($setting['date_format'], $listing['date_submitted']),             array(                 array(                     'title' => 'modify listing',                     'color' => 'primary',                     'href' => 'listings/modify/'.$listing['listing_id'],                     'text' => '<i class="fa fa-pencil"></i>'                 ),                 array(                     'title' => 'delete listing',                     'color' => 'danger',                     'href' => 'listings/delete/'.$listing['listing_id'],                     'text' => '<i class="fa fa-eraser"></i>',                     'confirm' => true                 )             )         );     }     return $listings;                        });   echo $output;  function responsive_table($headings = array(), $rows = array(), $sortable = false){      $output = '                                 <div class="table-responsive">                                     <table data-sortable class="table">                                         <thead>                                             <tr>                                                 ';      if(count($headings) > 0){          foreach($headings $heading){              $output .= '                                                 <th>'.$heading.'</th>';          }      }      $output .= '                                             </tr>                                         </thead>                                         <tbody>';      if(count($rows) > 0){          foreach($rows $row){              $output .= '                                             <tr>                                                 <td>'.$row.'</td>                                             </tr>';          }      }      $output .= '                                     </table>                                 </div>';      return $output;  } 

yes, looking http://php.net/manual/en/class.closure.php


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -