Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6364763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:12:24+00:00 2026-05-25T00:12:24+00:00

I have this snippet $clusters = new DirectoryIterator(/agents/); $cluster_array = array(); # Push each

  • 0

I have this snippet

$clusters = new DirectoryIterator("/agents/");
$cluster_array = array();

# Push each cluster into an array
foreach ($clusters as $fileinfo) {
    if ($fileinfo != "." && $fileinfo != ".." && $fileinfo != "conf") {
        array_push($cluster_array, $fileinfo->getFilename());
    }
}

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.

array([0]=>cluster_2, [1]=>cluster_1)

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.

After I have my array built, I wanted to scan thru each array and see how much free space was left with

foreach ($cluster_array as $cluster) {
    echo $cluster . " " . Server::server_free_space("/agents/" . $cluster, 2)."<br />";
}

that class method just uses disk_free_space() then converts the results into MB for me.

in-place of the echo statement I was going to do something like

if ((Server::server_total_space("/agents/" . $cluster, 2) / 3) > xMB) {

}

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.

does this make sense?

EDIT:

I ended up doing this an build the array kinda manually

$clusters = new DirectoryIterator("/agents/");
$cluster_array = array();
$cluster_count = 0;

# Push each cluster into an array
foreach ($clusters as $fileinfo) {
    if ($fileinfo != "." && $fileinfo != ".." && $fileinfo != "conf") {
        array_push($cluster_array, "cluster_" . $cluster_count += 1);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:12:24+00:00Added an answer on May 25, 2026 at 12:12 am

    You are using array_push() correctly, however DirectoryIterator and related iterators iterate through the items of the underlying filesystem, the way the operating system provides them. This is not necessarily sorted the way one might expect (naturally sorted, for instance). For a little more on this, also see this faux bug report.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Perl snippet from a script that I am translating into Python.
I have this snippet I found. svn status | grep '\!' | awk '{print
I have this snippet of code private Templates retrieveFromCache(String name) { TemplatesWrapper t =
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
VS 2008 I have this code snippet I found on a VB website. But
Imagine i have this HTML snippet 4 times over for four different sections of
I have this JSP code snippet: <%@ taglib uri=http://java.sun.com/jsp/jstl/core prefix=c%> <c:choose> <c:when test=${var1.properties[\Item Type\]
I have encounters this abap snippet that I have difficulty to comprehend. call function
I have an xsd that looks like this (snippet): <xs:complexType name=IDType> <xs:choice minOccurs=1 maxOccurs=2>
Never thought I'd have this problem :) The following snippet of code works in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.