比较两个阵列,并与PHP一起从数组中的任何匹配对



我在数组和多维数组中很新,并且想知道如何比较两个数组的键=>值对(或一个带有两个不同键的键,带有两个不同的键包含数组?)并从每个数组中取消键=>值配对。

示例数组:

Array
(
    [from] => Array
        (
            [active] => 1
            [airport_ids] => 
            [group_name] => test adgrp
            [zone_id] => 12
            [creation_time] => 1234567890
        )
    [to] => Array
        (
            [active] => 1
            [airport_ids] => 
            [group_name] => test adgroup
            [zone_id] => 2
            [group_email] => test@group.com
        )
)

因此,from是基本键阵列,to是比较键阵列。我想迭代tofrom键阵列,查找匹配键,并比较两个匹配的值。

如果它们键=>值对匹配,请从 tofrom键阵列中取消键=>值。

如果在to中发现的密钥不在from中,请将其留在to数组中。但是,如果在to中发现的密钥在CC_11中找不到的键,请从from密钥数组中取消设置。

将上述数组变成这样的东西:

Array
(
    [from] => Array
        (
            [group_name] => test adgrp
            [zone_id] => 12
        )
    [to] => Array
        (
            [group_name] => test adgroup
            [zone_id] => 2
            [group_email] => test@group.com
        )
)

@meta尝试以下概念:

<?php
    $arr1 = 
            array
            (
                "from" => array
                    (
                        "active" => 1,
                        "airport_ids" => null,
                        "group_name" => "test adgrp",
                        "zone_id" => 12,
                        "creation_time" => 1234567890
                    ),
                "to" => array
                    (
                        "active" => 1,
                        "airport_ids" => null,
                        "group_name" => "test adgroup",
                        "zone_id" => 2,
                        "group_email" => "test@group.com"
                    )
            );
    echo "<pre>";
    print_r($arr1); //before
    foreach($arr1["from"] as $key => $value) {
      foreach($arr1["to"] as $key1 => $value1) {
        if($key == $key1 && $value == $value1){
            unset($arr1["from"][$key], $arr1["to"][$key1]);
            break;
        }
      }
    }
    echo "<pre>";
    print_r($arr1); //after

相关内容

  • 没有找到相关文章

最新更新