PHP:包含来自未知文件夹的已知文件名

I am making a website the tech-tree of a game a friend is making. The tech-three itself is just a list of links going from one page to the other. The variables for each page are stored in a php file e.g.: mining.php. I don't want to have a massive list of files all in one folder. So far all I've managed to do is sort them into just the first branches of the tree with this:

$path = glob('tree/*/'.$page.'.php');
if ($path[0]) {
    include $path[0];

Ideally I want to be able to access the file from anywhere in the tree.
e.g.: The file mining.php would be at tree/strength/mining.php. And the file pickaxe.php would be at tree/strength/mining/pickaxe.php. But I would be able to include either one with the same include. What could i use to get my known filename from any folder or subfolder in the tree folder.

I worked out an answer for myself (it took me a few hours but this will make it easier to sort through the hundred of files that i will eventually have):

$count = 0;
$path = 'tree/*/';
$file = glob($path.$page.'.php');
while ((strpos($file[0], $page) == false) and ($count != 10)) {
    $file = glob($path.$page.'.php');
    $path .= '*/';
    $count++;
}
if (strpos($file[0], $page) == true) {
    include $file[0];

Just make sure you know how many folders you have and make (count == #) higher.

That's not how include is made to work. If you want to go on, walk the folders and check if is_file, then you caninclude, or better, require_once.

I would recommend you use namespaces

This will allow you to not only separate your classes pathwise, but also concept-wise.

Here's an example. Say you have class Mining in path tree/strength/mining.php if you give that class a namespace Tree\Strength you instantly know where that class lives at. You can even use an autoloader to have it resolve the file and load it automatically.

Autloader example adapted from http://www.php-fig.org/psr/psr-4/examples/

<?php   
spl_autoload_register(function ($class) {

   $base_dir = __DIR__; //Directory where your "package" lives

    $file = $base_dir . str_replace('\\', '/', $class) . '.php';

    // if the file exists, require it
    if (is_readable($file)) {
        require $file;
    }
});

Whenever you request something to do with class \Tree\Strength\Mining the autoloader kicks in and checks if $base_dir/Tree/Strength/Mining.php exists. You can have multiple autoloaders chained, however this only works for classes within a file with the same name.