title: How to "rtrim" a PHP array (remove empty elements ONLY towards the END of the array) and avoid a for or similar loop if possible
body: <p>Much like <code>rtrim()</code> to a string, how do I remove the empty elements of an array only after the last non-empty element towards the end of the array while avoiding a <code>for</code> or similar loop and possibly using PHP's array functions instead?</p>
  
  <p>I'm actually looking for the fastest/most efficient/elegant way, but if this is not possible without a <code>for</code> or similar loop or I'm mistaken about "fast/efficient/elegant" especially with PHP's array functions then I'd be more than happy to learn/know what's best. Thanks.</p>
  
  <p>Other assumptions:</p>
  
  <ol>
  <li>There can be a series of single or consecutive empty elements before the last non-empty element in the array.</li>
  <li>No need to worry about an empty array, but if this case is covered it's totally fine.</li>
  </ol>
  
  <p>For example:</p>
  
  <pre><code>Array
  (
      [0] =&gt; ""
      [1] =&gt; "text"
      [2] =&gt; "text"
      [3] =&gt; ""
      [4] =&gt; "text"
      [5] =&gt; ""
      [6] =&gt; ""
      [7] =&gt; "text"
      [8] =&gt; ""
      [9] =&gt; ""
  )
  </code></pre>
  
  <p>would end up being:</p>
  
  <pre><code>Array
  (
      [0] =&gt; ""
      [1] =&gt; "text"
      [2] =&gt; "text"
      [3] =&gt; ""
      [4] =&gt; "text"
      [5] =&gt; ""
      [6] =&gt; ""
      [7] =&gt; "text"
  )
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Array
  (
      [0] =&gt; "text"
      [1] =&gt; "text"
      [2] =&gt; "text"
      [3] =&gt; "text"
      [4] =&gt; "text"
      [5] =&gt; "text"
      [6] =&gt; "text"
      [7] =&gt; ""
      [8] =&gt; ""
      [9] =&gt; ""
  )
  </code></pre>
  
  <p>would end up being:</p>
  
  <pre><code>Array
  (
      [0] =&gt; "text"
      [1] =&gt; "text"
      [2] =&gt; "text"
      [3] =&gt; "text"
      [4] =&gt; "text"
      [5] =&gt; "text"
      [6] =&gt; "text"
  )
  </code></pre>