check an array of values with another array

Discussion in 'PHP' started by aadi92s, May 19, 2011.

  1. #1
    Hi friends,

    I have two arrays say original[] and input[]. In the first array i have 3 values
    1 
    2 
    3
    Code (markup):
    and in the second array i give 2 values

    2 
    3
    Code (markup):
    I want to check if these two values are present in the first array How can i do this?


    Thanx
     
    aadi92s, May 19, 2011 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    If i understood you correctly;

    <?php
    
    $array1 = array(1, 2, 3);
    $array2 = array(2, 3);
    
    foreach($array2 as $ele)
      {
      if(in_array($ele, $array1)) print "Array value $ele exists in array1\n";
      }
    
    ?>
    PHP:
    For more information on the above, which is pretty simple, see the in_array docs;

    http://php.net/manual/en/function.in-array.php
     
    lukeg32, May 19, 2011 IP
  3. spymobilephonesoftware

    spymobilephonesoftware Member

    Messages:
    228
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    46
    #3
    thanks this is very good link...learnt about in_array also know about how to use this array...
     
    spymobilephonesoftware, May 19, 2011 IP