PHP sort multidimensional array with custom order
<p>How do I sort a multidimensional array by a value, but with a custom order?</p>

<p>The multidimensional array will be something like:</p>

<pre><code>$attribute_content[0]['term_id'] = 76; 
$attribute_content[0]['content'] = "ratio";
$attribute_content[1]['term_id'] = 18;
$attribute_content[1]['content'] = "ideal condition";
$attribute_content[2]['term_id'] = 164;
$attribute_content[2]['content'] = "genotype";
$attribute_content[3]['term_id'] = 218;
$attribute_content[3]['content'] = "genetics";
$attribute_content[4]['term_id'] = 60;
$attribute_content[4]['content'] = "height";
</code></pre>

<p>and the ordering is according to the term_id, but will be:</p>

<pre><code>$order = array(18,164,218,60,76);
</code></pre>

<p>I've tried the following codes which re-order the array, but seemingly randomly:</p>

<pre><code>usort($attribute_content, function ($a, $b) use ($order) {
 $pos_a = array_search($a, $order);
 $pos_b = array_search($b, $order);
 return $pos_a - $pos_b;
});
</code></pre>

<p>and</p>

<pre><code>$weights = array_flip($order);
usort($attribute_content, function($x, $y) use($weights) {
    return $weights[$x['term_id']] - $weights[$y['term_id']];
});
</code></pre>

<p>Please help</p>