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

Expand Messages
• Thanks Minesh Shah, your solution works perfectly for me. array_keys , array_diff and array_diff_assoc doesn t satisfy my requirement
Message 1 of 6 , 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" =>
\$a2 = array("a" => "greenss", "b" => "browns", "c" =>"shiva","d" =>"red","e"
\$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" =>
> \$array2 = array("a" => "green", "b" => "brown", "c"
>
> 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]

[Non-text portions of this message have been removed]
• Hello Shiva, Thanks for your complements. If you need any kind of help regarding PHP then let me know anytime. As i am mastering in CakePHP and MVC based
Message 2 of 6 , Apr 6, 2010
• 0 Attachment
Hello Shiva,

Thanks for your complements. If you need any kind of help regarding PHP then
let me know anytime.

As i am mastering in CakePHP and MVC based architectures, you can ask and
refer any body, as i'm ready to help anybody for 24 * 7.

Thanks,
Minesh Shah

On Tue, Apr 6, 2010 at 1:02 PM, Shiva Kumar Mallikarjun <
shivakumar_rnm@...> wrote:

>
>
> 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@... <shahmineshr%40gmail.com>>
>
> To: bang-phpug@yahoogroups.com <bang-phpug%40yahoogroups.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" =>
> \$a2 = array("a" => "greenss", "b" => "browns", "c" =>"shiva","d"
> =>"red","e"
> \$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" =>
> > \$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!
>
>
> [Non-text portions of this message have been removed]
>
>
>

[Non-text portions of this message have been removed]
• Hi Shiva, check this out. greenss , b = brown , c = asdfsad , e = asdfsad , p = asdfsad ); \$array2 = array( a =
Message 3 of 6 , Apr 6, 2010
• 0 Attachment
Hi Shiva,

check this out.

<?php
\$array1 = array("a" => "greenss", "b" => "brown", "c" => "asdfsad","e" =>