, , .
<?php
$a1 = array(14181 => array('industries' => array('weight' => "105652", 'count' => "11")),
48354 => array('industries' => array('weight' => "508866", 'count' => "10")));
$a2 = array(16434 => array('business_types' => array('weight' => "104614", 'count' => "1")),
48354 => array('business_types' => array('weight' => "103610", 'count' => "10")));
foreach($a2 as $a2k => $a2v)
{
foreach($a2v as $a2vk => $a2vv)
{
$a1[$a2k][$a2vk] = $a2vv;
}
}
printf("Output:\n");
print_r($a1);
printf("Output:\n");
print_r($a1);
:
Output:
Array
(
[14181] => Array
(
[industries] => Array
(
[weight] => 105652
[count] => 11
)
)
[48354] => Array
(
[industries] => Array
(
[weight] => 508866
[count] => 10
)
[business_types] => Array
(
[weight] => 103610
[count] => 10
)
)
[16434] => Array
(
[business_types] => Array
(
[weight] => 104614
[count] => 1
)
)
)
, , .
: , , . . :
<?php
$a1 = array(14181 => array('industries' => array('weight' => "105652", 'count' => "11")),
48354 => array('industries' => array('weight' => "508866", 'count' => "10")));
$a2 = array(16434 => array('business_types' => array('weight' => "104614", 'count' => "1")),
48354 => array('business_types' => array('weight' => "103610", 'count' => "10")));
if(count($a1) <= count($a2))
{
$res = my_merge($a1, $a2);
}
else
{
$res = my_merge($a2, $a1);
}
function my_merge($a1, $a2)
{
$res = array();
foreach($a1 as $a1k => $a1v)
{
if(array_key_exists($a1k, $a2))
{
$res[$a1k] = array_merge($a1[$a1k], $a2[$a1k]);
}
}
return $res;
}
printf("Output:\n");
print_r($res);
:
Array
(
[48354] => Array
(
[industries] => Array
(
[weight] => 508866
[count] => 10
)
[business_types] => Array
(
[weight] => 103610
[count] => 10
)
)
)