对PHP数组使用文本文件

对PHP数组使用文本文件,php,arrays,Php,Arrays,我的脚本中有这样一个数组 $acceptedID = array ('su', 'root'); su root asdf etc. 我认为最终将很难添加更多,因为这个数组将变得非常长。所以我想知道是否有可能有这样一个外部文件 $acceptedID = array ('su', 'root'); su root asdf etc. 并在脚本中以 $acceptedID = array ('su', 'root', 'asdf', 'etc.'); 并使其随着外部文本文件的更改而不断

我的脚本中有这样一个数组

$acceptedID = array ('su', 'root');
su
root
asdf
etc.
我认为最终将很难添加更多,因为这个数组将变得非常长。所以我想知道是否有可能有这样一个外部文件

$acceptedID = array ('su', 'root');
su
root
asdf
etc.
并在脚本中以

$acceptedID = array ('su', 'root', 'asdf', 'etc.'); 
并使其随着外部文本文件的更改而不断更改。有没有办法做到这一点?同样,在数组存在之后,它必须运行and if语句来查看它是否在数组中

if (in_array($id, $acceptedID))
        return 'YES';
    else
        return 'NO';    

文件-将整个文件读入数组

使用这种方式,是否:


您只需将阵列保存在外部文件中,并将其包含在所需的位置:

//commands.php

// This file just contains a return statement which returns the the array
// with the commands

return array(

    'su',
    'root',
    'other',

);
// You can include your array anywhere you want
$validIds = include('commands.php');  
//yourscript.php

// This file just contains a return statement which returns the the array
// with the commands

return array(

    'su',
    'root',
    'other',

);
// You can include your array anywhere you want
$validIds = include('commands.php');  

这4个文件是在1个文件夹中,还是在1个文件中有4行?
acceptedd=file('myList.txt',file_IGNORE_NEW_line | file_SKIP_EMPTY_line)
@MohammadAbuShady在1个文件中有4行我在_array()中得到这个
,当试图运行if语句时,参数2应该是数组,在script.php的第5行给出布尔值