2013-01-23 114 views
2

文件,我有這樣的代碼包括在陣列

$__routes = array(

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

); 

,我有這樣的

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

我想包括在 「$ __路線陣」

使用example.php文件使用example.php文件

東西能像

$__routes = array(

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

include 'example.php'; 

); 

PLE我怎麼能做到這一點?

回答

3

如果不改變的例子。 PHP。每個文件都必須是有效的PHP代碼,因爲包含只發生在運行時(即達到此確切代碼行時),而不是解析時(即文件被加載時)。

一種方法可以完成你需要將

使用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'); 
+0

非常感謝你 – user2005646

0

如果我正確理解你的意圖,你可以包括一個文件到另一個和合並的數組:

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

其中$array2等於:

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

非常感謝你 – user2005646