doufan2541 2013-10-31 13:42
浏览 44
已采纳

在PHP中将令人困惑的逻辑与两个数组匹配?

I have this array which provides Geo-restriction information from API, this is an array list of countries where content is being BLOCKED :

Array ( [0] => GU [1] => PR [2] => CA [3] => VI [4] => US [5] => UM [6] => AS [7] => MP [8] => DE )

Now, I have another array which stores country-wise proxy information like this :

$proxies['US'] = 'my_us_proxy_url;
$proxies['DE'] = 'my_de_proxy_url;
$proxies['UK'] = 'my_uk_proxy_url;
$proxies['NL'] = 'my_nl_proxy_url;

I want to get value of the proxy which will allow user to bypass the country restriction i.e. a $proxies[KEY] value where KEY does not exist in the first array.

This is one of the snippet I tried but like everything else this is not the logic what is needed.

            $isBlocked = array_values;
            //print_r($isBlocked);
            if (in_array('US',$isBlocked))
            {
                echo 'US Blocked';
                foreach ($isBlocked as $value) {

                    if (!array_key_exists($value,$proxies)){
                        //Find first non blocked proxy and continue
                        echo "<br/>" . $value ;
                    }
                }

            }
  • 写回答

3条回答 默认 最新

  • doujiang5211 2013-10-31 13:45
    关注

    Use $key => $value structure in your foreach loop:

    foreach ($proxies as $key => $value) {
        if (!in_array($key, $isBlocked)){
            //Find first non blocked proxy and continue
            echo "<br/>" . $value ;
        }
    }
    

    Demo!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?