2017-10-08 32 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>"; 
?> 

我希望能幫到你。

問候。