SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Comparing 2 arrays IF and ONLY IF Array_A doesn't have values found in Array_B?

    I need to compare 2 arrays: Array_A and Array_B. I then want to assign to Array_A the values found in Array_B (without deleting what's already in Array_A) IF and ONLY IF the values found in Array_B are not already in Array_A.

    In my mind, I'm thinking I need to use 2 FOREACH loops, but then I came across array_dif() and in_array()...

    Advice is appreciated... Which approach should I use?

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    4,826
    Mentioned
    142 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $finalArray array_merge($array1array_diff($array1$array2)); 
    Be sure to congratulate xMog on earning April's Member of the Month
    Go ahead and blame me, I still won't lose any sleep over it
    My Blog | My Technical Notes


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •