简体   繁体   English

包含在PHP中的问题

[英]problem with include in PHP

I have a php file called Route.php which is located on: 我有一个名为Route.php的php文件,它位于:

/var/www/api/src/fra/custom/Action 在/ var / WWW / API / src目录/ FRA /自定义/行动

and the file I want to include is in: 我要包含的文件位于:

/var/www/api/src/fra/custom/ 在/ var / WWW / API / src目录/ FRA /自定义/

So what I have inside route php is an absolute path to the two php file I want to include: 所以我在路由php内部是我想要包含的两个php文件的绝对路径:

<?php

 include '/var/www/api/src/frapi/custom/myneighborlists.php';
 include '/var/www/api/src/frapi/custom/mynodes.php';

............
...........

?>

These two file has an array of large amount of size that I want to use in Route.php. 这两个文件有一个大量的数组,我想在Route.php中使用它。 When I do vardump($global) it just returns NULL. 当我执行vardump($ global)时,它只返回NULL。 What am I missing here? 我在这里错过了什么?

UPDATE: 更新:

I did an echo on the included file and it prints something, so therefore it is included.. however I can't get access that array... when I do a vardump on the array, it just returns NULL! 我对包含的文件做了一个回音并且它打印了一些内容,因此它被包含在内..但是我无法访问该数组...当我在数组上执行vardump时,它只返回NULL!

I did add a global $myarray inside the function in which I want to access the array from the other php file 我在函数中添加了一个全局$ myarray,我希望从其他php文件中访问该数组

Sample myneighborlists.php: 示例myneighborlists.php:

<?php

$myarray = array(
1=> array(3351=>179),
2=> array(3264=>172, 3471=>139),
3=> array(3467=>226),
4=> array(3309=>211, 3469=>227),
5=> array(3315=>364, 3316=>144, 3469=>153),
6=> array(3305=>273, 3309=>171),
7=> array(3267=>624, 3354=>465, 3424=>411, 3437=>632),
8=> array(3302=>655, 3467=>212),
9=> array(3305=>216, 3306=>148, 3465=>505),
10=> array(3271=>273, 3472=>254),
11=> array(3347=>273, 3468=>262),
12=> array(3310=>237, 3315=>237));

?>
A better approach

define('APP_DIR', '/var/www/api/src/fra/custom');
include(APP_DIR.'/mynodes.php');

set_include_path("/var/www/api/src/fra/custom"); 通过set_include_path( “/无功/网络/ API / SRC / FRA /自定义”);

Then include your files. 然后包括您的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM