Within the function below, the $myrecentposts variable holds an accumulation of the five latest posts. How do i take these 5 posts and reorder them before they're written towards the for-loop to ensure that they're purchased by their publish-title index within the array?

function getLatestPostsAndSort($post)
{
    $myrecentposts = get_posts(
        array('post__not_in' => get_option('sticky_posts'), 
        'numberposts' => 5
    )
 //NEED TO RESORT THE ARRAY HERE BY [POST-TITLE]
    foreach($myrecentposts as  $idxrecent=>$post)
    {   
    ?><li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li><?php 
    }
}

PS: the apparent suggestion may be to drag them in the database within the preferred order. However, the get_posts() method offers no such option. The default order is as simple as publish date (latest first). Basically alter the to "title", it doesn't take publish date into account and rather just pulls the whole publish collection and orders them by title.

You should use php's usort function: http://php.net/manual/en/function.usort.php

http://php.net/manual/en/function.usort.php

You should utilize usort()

In most cases, you are able to sort an assortment like:

usort($myrecentposts, function($a, $b) {
   return strcmp($a['title'], $b['title']); 
});

You have to adjust title to become regardless of the actual title of the bottom line is.

If this sounds like wordpress, then with different quick Search, it appears like it may be:

usort($myrecentposts, function($a, $b) {
   return strcmp($a->post_title, $b->post_title); 
});

Without having PHP 5.3, then you will want to maneuver that anonymous function right into a real one like:

function sort_post_by_title($a, $b) {
   return strcmp($a->post_title, $b->post_title); 
}
usort($myrecentposts, 'sort_post_by_title');