Entity filed query for sorting by title and weight both? "i need to display data in alphabetical oredr if weights are in same number(1,1,1)condition ,if weights like(1,2,3) condition need to display data weight based ASC order" i'm using below code alphabetical sorting working good in same weights condition, but weight based condition not working please help me

               $query = new EntityFieldQuery();

               $query-&gt;entityCondition('entity_type', 'node')

              -&gt;entityCondition('bundle', 'closing_team')
              -&gt;fieldCondition('field_homebranch', 'tid',   $node-&gt;field_closing_team_categories['und']['0']['tid'])
              -&gt;fieldCondition('field_featured','value','No','=')
              -&gt;propertyOrderBy('title', 'ASC');

              $result = $query-&gt;execute();
              $nids = array_keys($result['node']);
              $news_items2 = node_load_multiple($nids);
                /*echo "&lt;pre&gt;";
                print_r($news_items2);
                echo "&lt;/pre&gt;";exit;*/

             function element_sort1($a, $b) {
             $a_weight = (is_array($a) &amp;&amp; isset($a ['#weight'])) ? $a ['#weight'] : 0;
             $b_weight = (is_array($b) &amp;&amp; isset($b ['#weight'])) ? $b ['#weight'] : 0;
             if ($a_weight == $b_weight) {
              return 0;
                }
            return ($a_weight &gt; $b_weight);
                }


?>
This is more of a straight PHP question than a Drupal question, but it looks as if you have a bug in your value comparing function. It should return 1 if you want $a to sort greater than $b, it should return -1 for $b to sort greater than $a, and it should return 0 if the items should sort equally. But your function will only ever return 0 or 1. Try replacing your last return statement with return ($a_weight &gt; $b_weight) ? 1 : -1;