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

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

Expand Messages
  • Minesh Shah
    Apr 3 1:34 PM
    • 0 Attachment
      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@...> 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]
    • Show all 6 messages in this topic