dongying6896 2015-06-19 20:45
浏览 12
已采纳

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.

  • 写回答

1条回答 默认 最新

  • douanye8442 2015-06-19 21:11
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭