Php包含多维数组

Hello I am having trouble accessing a multidimensional array that is on a separate php page. Example on index.php:

include 'scripts/test.php';
echo $test[1][1];

on test.php:

$test = array
(
array("One", "Two"),
array("Three", "Four")
);

Wanted Result:

Four

This works fine when I have the array on the same page as the echo, also the route is correct because this works fine when I'm using a normal array on the same test.php file.

Did you turn error reporting on? Does the include work? The code itself should work so I guess your problem is the include

  • Make sure the path is correct
  • Make sure you don't mix up absolute and relative paths

You could also use $_SERVER['DOCUMENT_ROOT'] to be absolutely sure to include the right file:

<?php
    include($_SERVER['DOCUMENT_ROOT']."/scripts/test.php");
    doit();
?>

With your code your folder structure should look like this:

/scripts/test.php
/index.php

But first of all put this at the top of your index.php

error_reporting(E_ALL); 
ini_set('display_errors', '1');