0

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.

4
  • 2
    error_reporting(E_ALL); ini_set('display_errors', '1'); Commented Jun 19, 2015 at 20:47
  • 3
    You included Wanted Result, but what is the Actual Result? Commented Jun 19, 2015 at 20:51
  • Oh I'm sorry this echo isn't loading anything at all. The page still loads but this echo does not actually display anything new. Commented Jun 19, 2015 at 21:01
  • you must be lost some kind of config, or other thing, I make files and test it and works fine. Commented Jun 19, 2015 at 21:03

1 Answer 1

3

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.