Create pagination in theme('table') when not using SQL query I would like to create a pager in the table when there is fix amount of rows.

The method suggested on internet creates table, and it fetches data by using sql query, but i want to create a table from the data from the array.

visitedgroups = array('1','2','3','4');//It is an array of node id which are group entity
$header = array(
                array('data' =&gt; t('Group Name')),
                array('data' =&gt; t('Group Since')),
                array('data' =&gt; t('Join')),
            );
            $rows = array();
            foreach ($visitedgroups as $groupid) {
                $groupnode = node_load($groupid);
                $createdtime = format_interval((time() - $groupnode-&gt;created) , 2) . t(' ago');
                $joinlink = l('Join Group', 'group/node/'. $groupnode-&gt;nid.'/subscribe');
                $rows[] = array( l($groupnode-&gt;title, 'node/'. $groupnode-&gt;nid),
                                                t($createdtime),
                                                $joinlink,
                                    );
            }
            $output .= t('Recently visited groups by you, in which you are not member.');
            $output .= theme('table', array('header' =&gt; $header, 'rows' =&gt; $rows, array('class' =&gt; array('group-visited-table')))).theme('pager');


The above code generates the table and working fine. But i want to add pager in the table.
From the references on internet i found that people adds,


  $query =
  $query->extend('TableSort')->extend('PagerDefault')->limit(10);


ahead of $query->execute(), but i don't have query.

So how can i apply pager in this scenario..
Try the following function:

/**
 * An generic array pager for Drupal.
 * For Drupal 5 and 6, the default limit is 10. For Drupal 7 it is 9.
 */
function pager_array_splice($data, $limit = 9, $element = 0) {
  global $pager_page_array, $pager_total, $pager_total_items;
  $page = isset($_GET['page']) ? $_GET['page'] : '';

  // Convert comma-separated $page to an array, used by other functions.
  $pager_page_array = explode(',', $page);

  // We calculate the total of pages as ceil(items / limit).
  $pager_total_items[$element] = count($data);
  $pager_total[$element] = ceil($pager_total_items[$element] / $limit);
  $pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
  return array_slice($data, $pager_page_array[$element] * $limit, $limit, TRUE);
}

$output = pager_array_splice($yourarray, 5);  // 5 is per page values


See Paging non-SQL data for more details.