Sorting multidimensional array by key alphabetically
<p><strong>Trying to sort by this multidimensional array by screen name:</strong></p>

<pre><code>//Looping through this for each member of a group
unset($member_info);
$member_info-&gt;id           =   $member-&gt;id;
$member_info-&gt;screen_name  =   $member-&gt;screen_name;
$member_info-&gt;first_name   =   $member-&gt;first_name;
$member_info-&gt;last_name    =   $member-&gt;last_name;
$member_info-&gt;email        =   $member-&gt;email;

//Sort member_info by screen name
$member_array = sort_by_array_key($member_info,$member_info-&gt;screen_name,'ASC');
$member_list[] = $member_array;
</code></pre>

<p><strong>Sort function:</strong></p>

<pre><code>function sort_by_array_key($array,$sort_key,$dir = 'ASC') {
    usort($array, function($a,$b) use ($sort_key){
        return strnatcasecmp($a["$sort_key"], $b["$sort_key"]);
    });
    if ( $dir == 'DESC' ) { return array_reverse($array); }
    else { return $array; }
}
</code></pre>

<p><strong>As an example, screen names are currently in this order even after I run the sort function:</strong> </p>

<pre><code>newUser
Chris
Carlos
Jason
</code></pre>

<p>I am probably applying the sort at the wrong time but after looking at other similar examples here I was having trouble with this, any help is appreciated, thanks!</p>
