Sort view before print
I don't know where $nodeids comes from, but I expect it's an array of nids from a database query? If so, you're effectively running a view with a view and can probably get away without writing any code for hooks.

Therefore, you can either:


Sort the $nodeids yourself with uasort() which will mean probably returning more fields to sort with and maybe writing your own comparison function.
Let Views handle all of this, thus gaining access to the UI and all it's powers.


The latter 'view within a view' approach is better for sustainability and sanity because it uses the Views UI and theme layers more consistently. A good approach that's worked for me is:


Make a view that can either:

return the properly sorted $nodeids, or;
get it to take an argument of a comma-separated list of nids you can pass implode(',', $nodeids) to.

use Views PHP to add a field that can contain your views_embed_view($view, block_1, $nid), probably with $nid replaced by $row-&gt;nid but will depend on your setup.
Add any sorting or sorting code to the view you want.