How to sort field_info_instances return value by field weight? I'm using field_info_instances() to retrieve the information for all the fields used by a content type, for example calling it as field_info_instances('node','bundle_name').
In the returned array, the fields aren't ordered as I expected. I need to get the fields ordered per weight.
For example, a field weight is 8, in the Manage fields list.



Despite this, it's shown on the top, in the output from field_info_instances().



Is there any possibility to get the fields ordered?
You probably want something like this

$info = field_info_instances('node','bundle_name');

uasort($info, function($a, $b) {
  $a_weight = (is_array($a) &amp;&amp; isset($a['widget']['weight'])) ? $a['widget']['weight'] : 0;
  $b_weight = (is_array($b) &amp;&amp; isset($b['widget']['weight'])) ? $b['widget']['weight'] : 0;

  if ($a_weight == $b_weight) {
    return 0;
  }

  return ($a_weight &lt; $b_weight) ? -1 : 1;
});

// $info is now sorted by weight.