Skip to content

Instantly share code, notes, and snippets.

@robertbasic
Created April 1, 2013 19:32
Show Gist options
  • Select an option

  • Save robertbasic/5287121 to your computer and use it in GitHub Desktop.

Select an option

Save robertbasic/5287121 to your computer and use it in GitHub Desktop.
<?php
$arr1 = array(
'CustomerId' => NULL,
'CsgHeaderInfo' => array(
'ConversationId' => NULL,
'Region' => NULL,
'RoutingArea' => "83513001",
),
'SearchFilter' => array (
'AccountId' => "8351300110000561",
'CurrentItems' => "True",
'HistoryItems' => "False",
'LocationId' => NULL,
'PendingItems' => "True",
)
);
$arr2 = array (
'method' => "GetCurrentServices",
'CsgHeaderInfo' => array (
'RoutingArea' => "83513001"
),
'SearchFilter' => array(
'AccountId' => "8351300110000561",
'CurrentItems' => "True",
'HistoryItems' => "False",
'PendingItems' => "True"
)
);
$realResult = array();
$result = array_uintersect_assoc($arr1, $arr2, function ($a1, $a2) use (&$realResult, $arr1) {
if (!is_array($a1) && !is_array($a2)) {
if ($a1 === $a2) {
$realResult[array_search($a1, $arr1)] = $a1;
}
} else if (is_array($a1) && is_array($a2)) {
foreach ($a1 as $k1 => $v1) {
foreach ($a2 as $k2 => $v2) {
if ($k1 == $k2 && $v1 == $v2) {
$realResult[array_search($a1, $arr1)][$k1] = $v1;
}
}
}
}
});
var_dump($realResult);
/*
array(2) {
'CsgHeaderInfo' =>
array(1) {
'RoutingArea' =>
string(8) "83513001"
}
'SearchFilter' =>
array(4) {
'AccountId' =>
string(16) "8351300110000561"
'CurrentItems' =>
string(4) "True"
'HistoryItems' =>
string(5) "False"
'PendingItems' =>
string(4) "True"
}
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment