简体   繁体   中英

problem with include in PHP

I have a php file called Route.php which is located on:

/var/www/api/src/fra/custom/Action

and the file I want to include is in:

/var/www/api/src/fra/custom/

So what I have inside route php is an absolute path to the two php file I want to include:

<?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. When I do vardump($global) it just returns 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!

I did add a global $myarray inside the function in which I want to access the array from the other php file

Sample 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");

Then include your files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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