一种方法是让您的counties.txt文件具有以下格式:
<?php
return array(
'country1',
'country2',
// etc.
);
Run Code Online (Sandbox Code Playgroud)
然后,只需将其包含在您的数组中,例如:
<?php
$arr = include('counties.txt');
Run Code Online (Sandbox Code Playgroud)
另一种方法是解析counties.txt如下:
<?php
$list = file_get_contents('counties.txt');
// Normalize the linebreaks first
$list = str_replace(array("\r\n", "\r"), "\n", $list);
// Put each line into its own element within the array
$arr = explode("\n", $list);
Run Code Online (Sandbox Code Playgroud)
无论哪种方式都有效,并且会产生相同的结果。