title: PHP: Remove empty values from array and shift values up
body: <p>I'm trying to create a function that shifts array values up a key if the previous key is empty and one after is set. E.g. this array:</p>
  
  <pre><code>array (size=4)
      'row1' =&gt; string 'row1' (length=4)
      'row2' =&gt; string '' (length=0)
      'row3' =&gt; string '' (length=0)
      'row4' =&gt; string 'row4' (length=4)
  </code></pre>
  
  <p>should become this after my function call:</p>
  
  <pre><code>array (size=4)
      'row1' =&gt; string 'row1' (length=4)
      'row2' =&gt; string 'row4' (length=4)
      'row3' =&gt; string '' (length=0)
      'row4' =&gt; string '' (length=0)
  </code></pre>
  
  <p>I do have a working function, however, it uses a lot of if statements and I'm 100% sure that it could be done more efficiently, any ideas on how to achieve efficiently?</p>
  
  <p>Thanks</p>