Sort multidimensional array by a particular value (using asort and rasort)
<p>I realize there are several other questions pertaining to this - but either they dont make sense to me, or don't work how I need.</p>

<p>I have an array that is easy to sort by the first value alphabetically by using <code>asort()</code> and <code>arsort()</code>. An example of my multidimensional array might be:</p>

<pre><code>[{"Name":"Amber","date":"","dealType":"B-Braun Medical, Inc.","id":"***@***.com","registered":0},{"Name":"Bob","date":"","dealType":"B-Braun Medical, Inc.","id":"***@***.com","registered":0},{"Name":"Hans","date":"","dealType":"B-Braun Medical, Inc.","id":"***@***.com","registered":0},{"Name":"Jeff","date":"","dealType":"B-Braun Medical, Inc.","id":"***@***.com","registered":0},{"Name":"Michael","date":"","dealType":"B-Braun Medical, Inc.","id":"***@***.com","registered":0}]
</code></pre>

<p>With using <code>asort()</code> and <code>arsort()</code> it is sorted by <code>"Name"</code> alphabetically or reverse alphabetical. Now I need the same functionality, only based on <code>"dealType"</code>.</p>

<p>I have tried a few examples already posted on Stackoverflow, but I must misunderstand them because they are not working. How might I accomplish this?</p>

<p><strong>EDIT</strong>
Jonathan gave the correct answer for alphabetical sorting, with a slight modification: </p>

<pre><code>//the custom function to do our sort
function cmp($a,$b){
    //get which string is less or 0 if both are the same
    $cmp = strcasecmp($a-&gt;dealType, $b-&gt;dealType);
    //if the strings are the same, check name
    return $cmp;
}
//sort using a custom function
usort($obj, 'cmp');
</code></pre>

<p>and this code below for reverse alphabetical sorting:</p>

<pre><code>//the custom function to do our sort
function cmp($a,$b){
    //get which string is less or 0 if both are the same
    $cmp = strcasecmp($b-&gt;dealType, $a-&gt;dealType);
    //if the strings are the same, check name
    return $cmp;
}
//sort using a custom function
usort($obj, 'cmp');
</code></pre>
