2015-04-15 43 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' 

做了一些假设,因为你的问题只有很少的信息,希望这有助于!