2017-10-08 52 views
0

我再次, 我不明白我怎么能实现一个外部文件(a.php)multidimensionak数组在其他文件(b.php)来使用它!php如何包括一个文件多个数组

a.php只会仅仅实现了代码:

<?php 
    $array[1][0] = array("gutes"=>"something_1"); 
    $array[2][0] = array("gutes"=>"something_2"); 
    $array[3][0] = array("gutes"=>"etc."); 
    $array[4][0] = array("gutes"=>"etc.2"); 
    //.. 
    //many many more. 
?> 

b.php包括:

<?php 
    //tried calls 
    //include("../path/a.php"); -> err 500 
    //@require_once("a.php"); -> err 500 
    //require("fehleranalyse_array_lebenslauf2.php"); ->err 500 
    //require_once("fehleranalyse_array_lebenslauf2.php"); 

    //strange, i did not get an err 500, but also not the right output 
    //i see Test: but not Test: something_1 
    //include a.php; 

    //just for own tests: without including paths and only with that it works well 
    //$array[1][0] = array("gutes"=>"something_1"); 

    $testname_array = "gutes"; 
    echo "Test: " . $array[1][0][$testname_array] . "<br>"; 
?> 

SRY基因,但我看不到我的失败! TY

+0

一个问题,是文件a.php和b.php在同一个文件夹或不同的文件夹? – Synkronice

+0

@Synkronice在同一个文件夹.. ../路径我试图说,路径是独立的... –

回答

0

嗨@ein_noch_mieser_progger

我已经测试通过以下方式和成功的所有工作:

使用include()

<?php 
    include('a.php'); 
    $testname_array = "gutes"; 
    echo "Test: " . $array[1][0][$testname_array] . "<br>"; 
?> 

使用要求()

<?php 
    require('a.php'); 
    $testname_array = "gutes"; 
    echo "Test: " . $array[1][0][$testname_array] . "<br>"; 
?> 

使用require_once()

<?php 
    require_once('a.php'); 
    $testname_array = "gutes"; 
    echo "Test: " . $array[1][0][$testname_array] . "<br>"; 
?> 

我希望能帮到你。

问候。