意想不到的“,”但我一辈子都找不到

unexpected "," but can't find it for the life of me

我是 运行 基于国家代码重定向用户的脚本,现在我得到的响应是

Parse error: syntax error, unexpected ',' in /home2/mcp/public_html/redirect/index.php on line 15

这是第 15 行:$country_codes = 'US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL';

此处使用:

if (in_array($var_country_code, array($country_codes))) {

当删除第 15 行并将其添加到 $country_codes 现在所在的位置时,给我:

if (in_array($var_country_code, array('US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL'))) {

它工作正常。

有人看到错误了吗? 如果您需要更多代码,请告诉我:)

谢谢!

顺便说一句,使用 GeoIP 插件。

你需要把它做成一个数组。

$country_codes = array('US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL');

然后是

if (in_array($var_country_code, $country_codes)) {

因为它已经是一个数组了。

您尝试像这样分配一个数组:

$country_codes = 'US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL';

虽然你应该这样做:

$country_codes = array('US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL');

或者像这样:

$country_codes = ['US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL'];