【问题标题】:unexpected "," but can't find it for the life of me出乎意料的“”,但我一辈子都找不到
【发布时间】:2015-05-17 04:27:09
【问题描述】:

我正在运行一个脚本来根据国家/地区代码重定向用户,现在我得到的响应是

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 插件。

【问题讨论】:

  • 你打算对第 15 行做什么,设置一个国家代码数组?
  • 是的,这样做更利于用户友好

标签: php arrays geo


【解决方案1】:

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

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

然后

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

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

【讨论】:

  • 我需要对if (in_array($var_country_code, array($country_codes))) {进行任何更改?
  • 太棒了,这就像一个魅力,教会了我我做错了什么,谢谢!
【解决方案2】:

你尝试这样分配一个数组:

$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'];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 2017-12-01
    相关资源
    最近更新 更多