-2

I'm running a script to redirect users based on country code, and right now the response I get is

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

This is line 15: $country_codes = 'US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL';

Used here:

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

When deleting line 15 and just adding it in where $country_codes sits right now, giving me:

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

it works fine.

Anyone that sees the error? If you need more code please let me know :)

Thanks!

Using the GeoIP plugin btw.

Snowlav
  • 325
  • 1
  • 12
  • 26

2 Answers2

3

You need to make it an array.

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

and then

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

because it will be an array already.

chris85
  • 23,846
  • 7
  • 34
  • 51
2

You try to assign an array like this:

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

while you should do it like this:

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

or like this:

$country_codes = ['US', 'CA', 'UK', 'AU', 'NZ', 'ZA', 'NL'];
n-dru
  • 9,285
  • 2
  • 29
  • 42