php如何在文件中包含多个数组

时间:2017-10-08 10:39:01

标签: php

再次,我 我无法理解如何在其他文件(b.php)中使用multidimensionak数组实现extern文件(a.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

1 个答案:

答案 0 :(得分:0)

你好@ein_noch_mieser_progger

我已经测试了以下方法,并且所有方法都成功运行:

使用include()

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

使用require()

<?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>";
?>

我希望能帮到你。

问候。