2

私はこのコードを持っています

$__routes = array(

"Home"                    => "index.php",
"Contact"                 => "contact.php",
"Register"                => "register.php",

);

そして、私はこのようなexample.phpファイルを持っています

"Support"                 => "support.php",
"Success"                 => "success.php",
"Act"                     => "activate.php",

「$__routes配列」にexample.phpファイルを含めたい

のようなもの

$__routes = array(

"Home"                    => "index.php",
"Contact"                 => "contact.php",
"Register"                => "register.php",

include 'example.php';

);

どうすればそれができますか?

4

2 に答える 2

4

example.php を変更せずにはいられません。インクルードは解析時 (つまり、ファイルのロード時) ではなく、実行時 (つまり、コードのこの正確な行に到達したとき) にのみ発生するため、各ファイルはそれ自体が有効な PHP コードである必要があります。

必要なものを達成する1つの方法は

example.php

return array(
    "Support"                 => "support.php",
    "Success"                 => "success.php",
    "Act"                     => "activate.php"
);

メインファイル

$__routes = array(
    "Home"                    => "index.php",
    "Contact"                 => "contact.php",
    "Register"                => "register.php"
) + (include 'example.php');
于 2013-01-23T23:00:16.530 に答える
0

あなたの意図を正しく理解している場合は、あるファイルを別のファイルに含めて、配列をマージできます。

$merged_aray = array_merge($__routes, $array2);

$array2等しい場所:

"Support"                 => "support.php",
"Success"                 => "success.php",
"Act"                     => "activate.php"
于 2013-01-23T22:59:49.240 に答える