关联数组foreach循环以加载所需的文件


associative array foreach loop to load required files

我正在尝试使用关联数组加载'config.php'中的所有文件。不同的值表示可以在哪里找到文件。然而,我一直得到一个错误输出:

无法加载:array.php、array.php、array.php、arrayphp、dir.php,dir.php,dir.php,dir.php,auth.php,authphp,auth.php,forms.php,forms.php,image.php、image.php、navigation.php、navigaton.php、navivation.php,navigation.php、stats.php、stats.hp、stats.hp.stats.php、,table.php,tables.php,tables.hp,tables..php,text.php,textphp,text.php,text.php,user.php,userphp,user.php,youtube.php,youtube.php,messages.php、messages.php,nemesis.php,nemesis.php,上传.php,上传php,上传php,upload.php,construct.php,construct_php,construction.php,construct.php,prepared_arrays.php,prepered_arrays.hp,prepared_arrays.php,prepared_arrays.php

我不知道为什么会发生这种情况,也不知道为什么它说文件无法加载4次。

<?php
    $require = array(
        'array.php' => 'f',
        'dir.php' => 'f',
        'auth.php' => 'f',
        'forms.php' => 'f',
        'image.php' => 'f',
        'navigation.php' => 'f',
        'stats.php' => 'f',
        'tables.php' => 'f',
        'text.php' => 'f',
        'user.php' => 'f',
        'youtube.php' => 'f',
        'messages.php' => 'c',
        'nemesis.php' => 'c',
        'upload.php' => 'c',
        'construct.php' => 't',
        'prepared_arrays.php' => 'l'
    );
    load($require);
    function load($require) {
        foreach ($require as $filename => $directory) {
            // init functions
            if ($directory = 'f') {
                $prep = FUNCTIONS_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
            // init classes
            if ($directory = 'c') {
                $prep = CLASSES_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
            // init templates
            if ($directory = 't') {
                $prep = TEMPLATES_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
            // init libs
            if ($directory = 'l') {
                $prep = LIBS_DIR . $filename;
                if (is_file($prep) && is_readable($prep)) {
                    require($prep);
                    $pass[] = $filename;
                } else {
                    $fail[] = $filename;
                }
            }
        }
        if (!empty($fail)) {
            if (!empty($pass)) {
                $passed  = implode(', ', $pass);
                $message = "Loaded: {$passed}";
                echo $message;
            }
            if (!empty($fail)) {
                $failure = implode(', ', $fail);
                $message = "Could not load: {$failure}";
                echo $message;
            }
            exit();
        }
    }
    ?>

$directory = 'l'应为$directory == 'l':)

PS同样适用于您的所有比较。它们是比较,而不是分配