Link to home
Start Free TrialLog in
Avatar of Insoftservice inso
Insoftservice insoFlag for India

asked on

php array diff

hi,
i have two array on coming from db and other from xml.

i have to merge it keeping in mind the order and its data.
as per order 'Array 1' has to be kept in higher order, but if its present in 'Array 2' then it's order has to be maintain accordingly and data has to be merge with 'Array 2' over here its for 'muk'

Array 1
Array
(
    [vinay] => Array
        (
            [payment_date] => 0
            [dnname] => vinay
            [dnprivate] =>
            [wbcrstmps] => 911789
            [dnforward] => 495232
            [dndoa] => 1337625000
            [dndoe] => 1337625000
        )

    [muk] => Array
        (
            [payment_date] => 0
            [dnname] => muk
            [dnprivate] =>
            [wbcrstmps] => 911789
            [dnforward] => 495232
            [dndoa] => 1337625000
            [dndoe] => 1337625000
        )
)
Array 2
Array
(
    [dxvdf.in] => Array
        (
            [emadminid] => no_email
            [wbcrstmps] => 911793
            [emtotid] => 5
            [WBRFNBR] => Array
                (
                    [EML] => 911793
                    [DOM] => 911793
                    [MOB] => 911793
                )
      )

      [muk] => Array
        (
            [emadminid] => muk
            [wbcrstmps] => 911793
            [emtotid] => 5
            [WBRFNBR] => Array
                (
                    [EML] => 911793
                    [DOM] => 911793
                    [MOB] => 911793
                )
      )
)


o/p

Array
(
    [dxvdf.in] => Array
        (
            [emadminid] => no_email
            [wbcrstmps] => 911793
            [emtotid] => 5
            [WBRFNBR] => Array
                (
                    [EML] => 911793
                    [DOM] => 911793
                    [MOB] => 911793
                )
      )

    [vinay] => Array
        (
            [payment_date] => 0
            [dnname] => vinay
            [dnprivate] =>
            [wbcrstmps] => 911789
            [dnforward] => 495232
            [dndoa] => 1337625000
            [dndoe] => 1337625000
        )

    [muk] => Array
        (
            [payment_date] => 0
            [dnname] => muk
            [dnprivate] =>
            [wbcrstmps] => 911789
            [dnforward] => 495232
            [dndoa] => 1337625000
            [dndoe] => 1337625000
          [emadminid] => muk
            [emtotid] => 5
            [WBRFNBR] => Array
                (
                    [EML] => 911793
                    [DOM] => 911793
                    [MOB] => 911793
                )
        )

      
)
SOLUTION
Avatar of StingRaY
StingRaY
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Insoftservice inso

ASKER

no i will check it out and let u know regarding it.
thx for reply
no,
it did not worked, as the o/p gives the data ay array 1 to for the common key (over here muk).

whereas muk value from array2 has to remain and the additional value has to be appended in it
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thx but its php4 and array_diff_key is for php5 , i am searching for its subsitiute
i did it in such fashion

$count = count($array2);
            $i=1;
            foreach($array1 as $dom => $domval)
            {
            // echo $dom;exit;
             $exist = array_key_exists($dom,$array2);
             if($exist)
             {
              $xmldom[] = $dom;
              // $details[$dom] = $array2[$dom];
             }
             else
             {
               $i++;
               $details[$dom] = $array1[$dom];
             }
            
            }
            
            if($i < $count)
            {
                    foreach($array2 as $domxml => $domxmlval)
                  {
                  $details[$domxml] = $array2[$domxml];
                  }

            }
will it do as expected.
please do let me know as i am out of my mind currently
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thx, did not chk but it was near to resolve my issue