I have 2 arrays A & B - how do I remove items in A that are found in B?

Discussion in 'PHP' started by Swamper, Oct 12, 2006.

  1. #1
    Do I just sequentially go through each element in B - check for it in A and delete if found or is there another way?

    Thanks.
     
    Swamper, Oct 12, 2006 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    $a = array('a', 'b', 'd', 'e', 'f');
    $b = array('a', 'b', 'c');	
    	
    $a = array_diff($a, $b);
    PHP:
     
    SoKickIt, Oct 12, 2006 IP
  3. Swamper

    Swamper Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I just found array_diff now too - thanks! :)

    (Silly me, dunno how I missed that)
     
    Swamper, Oct 12, 2006 IP