我在数组和多维数组中很新,并且想知道如何比较两个数组的键=>值对(或一个带有两个不同键的键,带有两个不同的键包含数组?)并从每个数组中取消键=>值配对。
示例数组:
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
是比较键阵列。我想迭代to
和from
键阵列,查找匹配键,并比较两个匹配的值。
如果它们键=>值对匹配,请从 to
和 from
键阵列中取消键=>值。
如果在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