2015-04-15 45 views
-6

我想寫這個數組寫入陣列格式提交

$array = [ 
    'key1' => 'value1', 
    'key2' => [ 
     'subkey1' => 'value3' 
    ], 
    'key3' => 'value4' 
]; 

的配置,這應該是這樣的:

的config.php

<?php 
return [ 
    'key1' => 'value1', 
    'key2' => [ 
     'subkey1' => 'value3' 
    ], 
    'key3' => 'value4' 
]; 
?> 

使用此格式以後我可以包括像這樣的文件:

index.php

$config = include 'config.php'; 

這是可能與一個共同的PHP函數?我知道,這對var_export和print_r是不可能的。

+0

而你的問題是? – Rizier123

+0

你可以給我們一個明確的說明你的要求是什麼... – phpfresher

+0

_Is這可能與一個普通的PHP函數嗎?_不,不是簡寫版本,可能與'var_export'雖然 – Ghost

回答

0

如果創建在config.php則加載的變量,當你有像這樣的的index.php文件:

的config.php

<?php 
$config = [ 
    'key1' => 'value1', 
    'key2' => [ 
     'subkey1' => 'value3' 
    ], 
    'key3' => 'value4' 
]; 
?> 

的index.php

include "config.php"; 
$value4 = $config['key3']; // 'value4' 

做了一些假設,因爲你的問題只有很少的信息,希望這有助於!