PHP用键array2匹配array1的值

时间:2018-10-01 14:51:14

标签: php

如何匹配键和值(缩写和国家/地区)并计算总百分比?

$def = array( "AF" => "Afghanistan", "AL" => "Albania", "DZ" => "Algeria", "AD" => "Andorra", ...)
$var      = ["AF", "AF", "DZ"];

结果: 66%阿富汗 33%阿尔及利亚

2 个答案:

答案 0 :(得分:0)

我们可以使用array_diff_key()比较两个数组的键和值,

<!DOCTYPE html>
<html>
    <body>

        <?php
        $a1=array("a"=>"red","b"=>"green","c"=>"blue");
        $a2=array("a"=>"red","c"=>"blue","d"=>"pink");

        $result=array_diff_key($a1,$a2);
        print_r($result);
        ?>

    </body>
</html>

希望,这会有所帮助。

答案 1 :(得分:0)

使用array_count_values

      volumeMounts:
        - mountPath: $JFROG_PATH
          name: secrets
        - mountPath: /config
          name: vault

3v4l.org demo