How to modify sort order using PHP? I want to re-order the results of a View using some arbitrary PHP ( the sort is not possible in SQL ).  I believe I could use either _views_pre_render(&amp;$view) or hook_views_post_execute(&amp;$view) to alter the order of the results. However the $view->result array only contains the number of results that the pager is set to, not the whole result set.

Is there some other method I can hook into the result generation process and alter the order of results using PHP ?
Views will always only return the results for the current page of results.

That is a benefit of paging, since you aren't retrieving all the data if users may only want to see some results.

If you want to sort after the results come from the database then you have to turn paging off and return all results. Then you can sort all the results and display them as you like.

[EDIT]

You mention in your comment potentially using hook_views_query_alter() to alter the paging out of the query but (without having actually tried) I don't think that would work without removing the paging all together, because PagerDefault::execute() does its thing to the SQL after you are altering.

If you want to pursue that idea though, what might potentially work though is you doing Query alteration (tagging) by adding an alter tag in hook_views_query_alter() and then implementing hook_query_TAG_alter(), which would run on the preExecute(), which should be after the pager has acted.

For example:

/**
 * Implements hook_views_query_alter().
 */
function MODULE_NAME_views_query_alter(&amp;$view, &amp;$query) {
  if ($view-&gt;name == 'VIEW_NAME' &amp;&amp; $view-&gt;current_display == 'DISPLAY_NAME') {
    // Add a query alteration tag so that we can alter the completed query before execution.
    $query-&gt;addTag('CUSTOM_TAG_NAME');
  }
}

/**
 * Implements hook_query_TAG_alter().
 *
 * Alter queries with the CUSTOM_TAG_NAME tag.
 */
function MODULE_NAME_query_CUSTOM_TAG_NAME_alter(QueryAlterableInterface $query) {
  // Alter the $query object here.
}