title: How To Sort Empty key & value in lower order if its null in php
body: <p>What I need </p>
  
  <ul>
  <li>i Need when [comment]='' Field  is Null Then it Should  be sort &amp; it would result in lower order.</li>
  <li><p>Array Structure</p>
  
  <pre><code>[0] =&gt; Array
  (
      [type] =&gt; CACDA
      [metadata] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [amount] =&gt; 320
                      [comment] =&gt; 
                  )
  
          )
  
  )
  
   [1] =&gt; Array
  (
      [type] =&gt; CVMA
      [metadata] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [amount] =&gt; 320
                      [comment] =&gt; Onsite After February 20
                  )
  
          )
  
  )
  </code></pre></li>
  </ul>
  
  <p>source code</p>
  
  <pre><code>              unset($data[0]);
              //store types and the arrays the belong to    
                  foreach($data as $k=&gt;$v){
                  $type[$v['type']][]=$k;
                  }
  
                  //loop types, creating result array
                  foreach($type as $k=&gt;$v){
                  $tmp=array(
                  'type'=&gt;$k,
                  'metadata'=&gt;array()
                  );
                  //loop all the arrays of this type
                  foreach($v as $w){
                  //store in TMP
                  $t=array(
                  'amount' =&gt; $data[$w]['amount'],
                  'comment' =&gt; $data[$w]['comment']
                  );
  
                 $t array structure
  
                                                                                   Array
                                      (
                                      [amount] =&gt; 320
                                      [comment] =&gt; 
                                      )
                                      Array
                                      (
                                      [amount] =&gt; 320
                                      [comment] =&gt; Onsite After February 20
                                      )
                                      Onsite After February 20Array
                                      (
                                      [amount] =&gt; 320
                                      [comment] =&gt; Onsite After February 20
                                      )
                                      Onsite After February 20Array
                                      (
                                      [amount] =&gt; 370
                                      [comment] =&gt; Onsite After February 20
                                      )
                                      Onsite After February 20Array
                                      (
                                      [amount] =&gt; 170
                                      [comment] =&gt; Onsite After February 20
                                      )
                  //sort TMP on EMPTY value
                  //usort($t,function ($a, $b) {
                  //if($a == '' &amp;&amp; $b != '') return 1;
                  //if($b == '' &amp;&amp; $a != '') return -1;
                  //if($b == 0){return 1;}
                  //return 0; 
                  //});
                  arsort($t['comment']);
                  //store 
                  $tmp['metadata'][]=$t;
                  }
                  $result[]=$tmp;
                  }
  </code></pre>
  
  <p>output of array  after sorting Should come Like ex</p>
  
  <pre><code>      [1] =&gt; Array
      (
          [type] =&gt; CVMA
          [metadata] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [amount] =&gt; 320
                          [comment] =&gt; Onsite After February 20
                      )
  
              )
  
      )
     [0] =&gt; Array
      (
          [type] =&gt; CACDA
          [metadata] =&gt; Array
              (
                  [0] =&gt; Array
                      (
                          [amount] =&gt; 320
                          [comment] =&gt; 
                      )
  
              )
  
      )
  </code></pre>
  
  <ul>
  <li><p>problem i having i have also tried with usort .</p></li>
  <li><p>i have tried with  arsort function but nothing is working for sorting .</p></li>
  <li><p>please suggest where i have done wrong .</p></li>
  <li><p>which sorting function i should use  for key &amp; value in php.</p></li>
  </ul>