Recursive tree folder function php not going into subfolders

I am currently working on a php file indexer and I need to create a recursive function to create an array that will contains the files and subfolders list of the parent folder, with the subfolders also being arrays containing their files and their subfolders (etc…). As it is a school project, I cannot use DirectoryRecursiveIterator and its siblings RecursiveIterator and DirectoryIterator.
My issue is that it scans the parent folder and finds the subfolders and files but does not go in subfolders to find files and subfolders.