title: DirectoryIterator and array_pop and foreachloop of array
body: <p>I have this snippet</p>
  
  <pre><code>$clusters = new DirectoryIterator("/agents/");
  $cluster_array = array();
  
  # Push each cluster into an array
  foreach ($clusters as $fileinfo) {
      if ($fileinfo != "." &amp;&amp; $fileinfo != ".." &amp;&amp; $fileinfo != "conf") {
          array_push($cluster_array, $fileinfo-&gt;getFilename());
      }
  }
  </code></pre>
  
  <p>this puts each folder it finds into my array, but my problem is that it keeps pushing the results at the begining of the array.</p>
  
  <pre><code>array([0]=&gt;cluster_2, [1]=&gt;cluster_1)
  </code></pre>
  
  <p>I want it to push the folders in order at the end of the array. I tried array_pop but i wasn't sure how to use it in this context.</p>
  
  <p>After I have my array built, I wanted to scan thru each array and see how much free space was left with</p>
  
  <pre><code>foreach ($cluster_array as $cluster) {
      echo $cluster . " " . Server::server_free_space("/agents/" . $cluster, 2)."&lt;br /&gt;";
  }
  </code></pre>
  
  <p>that class method just uses <code>disk_free_space()</code> then converts the results into MB for me.</p>
  
  <p>in-place of the echo statement I was going to do something like</p>
  
  <pre><code>if ((Server::server_total_space("/agents/" . $cluster, 2) / 3) &gt; xMB) {
  
  }
  </code></pre>
  
  <p>I wanted to create a folder into the first item in the array that has xMB available, if xMB isn't available then move onto the next array item and so on until it finds an array item that has the space required to make a new folder.</p>
  
  <p>does this make sense?</p>
  
  <p>EDIT:</p>
  
  <p>I ended up doing this an build the array kinda manually</p>
  
  <pre><code>$clusters = new DirectoryIterator("/agents/");
  $cluster_array = array();
  $cluster_count = 0;
  
  # Push each cluster into an array
  foreach ($clusters as $fileinfo) {
      if ($fileinfo != "." &amp;&amp; $fileinfo != ".." &amp;&amp; $fileinfo != "conf") {
          array_push($cluster_array, "cluster_" . $cluster_count += 1);
      }
  }
  </code></pre>