I'm having this problem.
Let's assume that I have a series of folders, inside of these folders, they have have a unlimited supply of sub folders and you can have an unlimited supply of files within this.
Using Recusion, I am trying to get the number of all of the files that exist within the sub directories, as well as this, get the total number of files from the sub sub directly.
I am using the following:
$SubSectionTotalCount = 0;
$SubSectionComplete = 0;
function GetStats($child, $groups, $progress, $resCount, $complete)
{
foreach($child->children as $childElement)
{
if($childElement->resources != null)
{
foreach($childElement->resources->groups as $groupss)
{
if(Check($groupss->id, $groups))
{
if(array_key_exists($childElement->parent_id, $progress))
{
if(array_key_exists($childElement->resources->id, $progress[$childElement->parent_id]['tasks']))
{
$complete++;
}
}
$resCount++;
var_dump($resCount);
}
}
}
GetStats($childElement, $groups, $progress, $resCount, $complete);
}
}
I currently have 4 sections (which therefore resCount should print 4) but instead, I am getting:
int 1
int 2
int 3
int 2
If I don't increment the variables, and just var_dump("getting here") I get the following:
Getting here
Getting here
Getting here
Getting here
So the recursion is working, however I don't understand why incrementing is not producing the desired output?
RecursiveDirectoryIteratorwhich helps with this sort of stuff.