Loading ...
Sorry, an error occurred while loading the content.

1579Re: [bang-phpug] Compare two array and return difference from both array

Expand Messages
  • Shiva Kumar Mallikarjun
    Apr 6, 2010
    • 0 Attachment
      Thanks Minesh Shah, your solution works perfectly for me.

      array_keys , array_diff and array_diff_assoc doesn't satisfy my requirement






      ________________________________
      From: Minesh Shah <shahmineshr@...>
      To: bang-phpug@yahoogroups.com
      Sent: Sun, 4 April, 2010 2:04:08 AM
      Subject: Re: [bang-phpug] Compare two array and return difference from both array


      Hello,

      here is a solution for you.

      $a1 = array("a" => "greenss", "b" => "brown", "c" =>"asdfsad", "e" =>
      "asdfsad","p" => "asdfsad");
      $a2 = array("a" => "greenss", "b" => "browns", "c" =>"shiva","d" =>"red","e"
      => "asdfsad");
      $res_a= array_keys($ a1);
      $res_b= array_keys($ a2);
      $result= array_unique( array_merge( $res_a,$res_ b));
      foreach($result as $k=>$v):
      if($a1[$v]== $a2[$v])
      continue;
      $status[]=$v;
      if(isset($a1[ $v]))
      unset($a1[$v] );
      if(isset($a2[ $v]))
      unset($a2[$v] );

      endforeach;

      echo "<pre>";
      print_r($status) ;

      On Sat, Apr 3, 2010 at 9:03 PM, Shiva Kumar Mallikarjun <
      shivakumar_rnm@ yahoo.com> wrote:

      >
      >
      > Hi All,
      >
      > i've two array, compare two array and return difference from both array
      > keys only..
      >
      > $array1 = array("a" => "greenss", "b" => "brown", "c" =>
      > "asdfsad","e" => "asdfsad","p" => "asdfsad");
      > $array2 = array("a" => "green", "b" => "brown", "c"
      > =>"shiva","d" =>"red","e" => "asdfsad");
      >
      > it should return
      >
      > array("a", "c", "d","p") .... list of different keys according to value.
      >
      > Thanks,
      >
      > Shiva
      > ____________ _________ _________ __
      >
      > The INTERNET now has a personality. YOURS! See your Yahoo! Homepage.
      > http://in.yahoo com/
      >
      > [Non-text portions of this message have been removed]
      >
      >
      >

      [Non-text portions of this message have been removed]





      Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! http://downloads.yahoo.com/in/internetexplorer/

      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic