【发布时间】:2016-10-03 09:20:53
【问题描述】:
我正在使用 php geoip_country_code_by_name 函数从如下所示的数组中为不同国家/地区提供不同的内容:
<?php
$content = array(
'GB' => array(
'meta_description' => "Description is here",
'social_title' => "Title here",
'country_content_js' => "js/index.js",
),
'BR' => array(
'meta_description' => "Different Description is here",
'social_title' => "Another Title here",
'country_content_js' => "js/index-2.js",
),
);
?>
如何检查用户所在国家/地区是否在数组中,如果没有将“GB”设置为默认值?
我正在使用它来检查国家/地区:
$country = ( isset($_GET['country']) && !empty($_GET['country']) ? $_GET['country'] : ( isset($_SESSION['country']) && !empty($_SESSION['country']) ? $_SESSION['country'] : ( isset($_COOKIE['country']) && !empty($_COOKIE['country']) ? $_COOKIE['country'] : geoip_country_code_by_name(ip()) ) ) );
【问题讨论】:
-
也许你应该考虑in_array()
-
嗯,这取决于您如何检查国家/地区是否不在数组中,一种方法是使用三元运算符。
-
我不确定如何检查该国家/地区是否不在数组中