我使用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()](http://php.net/手动/ en/function.in-array.php) – Alex
那么,这取决于你如何检查国家是否不在数组中,一种方法是使用三元运算符。 – Epodax
我不知道如何检查该国是否不在阵列中 –