title: Sorting an array in a foreach loop if value is not empty
body: <p>I have this foreach loop and i was wondering if there could be a way to sort the array accurding to a value if it's not empty to be at top and the rest goes down. here what I have done so far:</p>
  
  <pre><code>foreach ((array)$accounts as $v=&gt;$k){
          if(!empty($k)) {
                  echo $v;
                  echo "&lt;/br&gt;";
                  echo $k;
                  echo "&lt;/br&gt;";
          } else {
              echo $v;
              echo "&lt;/br&gt;";
          }
      }
  </code></pre>
  
  <p>Note: <code>$k</code> returns either a string or it's just empty not <code>NULL</code></p>
  
  <p>The ouput is something like:</p>
  
  <pre><code>k1
  v1
  k2
  k3
  v3
  </code></pre>
  
  <p>As you can see <code>k2</code> has no value. i want it to be at the bottom as it doesn't have a value.</p>
  
  <p>Outputing the array directly with <code>print_r($accounts, TRUE)</code>:</p>
  
  <pre><code>Array
  (
      [TwitterSecKey] =&gt; Twitter Sec Key
      [GoogleSecKey] =&gt; 
      [InstagramSecKey] =&gt; Instagram Sec Key
      [FacebookSecKey] =&gt; 
  )
  </code></pre>
  
  <p>As you can see Google and Facebook don't have values. so i want them to be at the bottom.</p>