comparing two arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gerard Matthew

    comparing two arrays

    What i need to do is compare two arrays and return an array that only
    has those that are not in the main table.It's similar to what you could
    do with SQL.

    Array 1 - List of Everything
    Array 2 - List of Some of Array 1

    What i want to obtain is Those of Array 1 that are not in Array 2. I
    would prefer not to do the following:

    function getUnique($arra y1, $array2) {

    foreach ($array1, $key => $value) {
    $array2_key = array_search($a rray2,$value)

    if ($array2_key === false)
    $result_array[] = $value;


    }

    return $result_array;
    }

    Is there any simplier way of doing this...any predefined function in
    php that could do this??

    Regards,
    Gerard Matthew.

  • Ewoud Dronkert

    #2
    Re: comparing two arrays

    Gerard Matthew wrote:[color=blue]
    > What i want to obtain is Those of Array 1 that are not in Array 2.[/color]



    --
    E. Dronkert

    Comment

    • Gerard Matthew

      #3
      Re: comparing two arrays

      Thanks

      Comment

      • Khai

        #4
        Re: comparing two arrays

        Isn't it funny how we sometimes reinvent the wheel unpurposely? I did that
        once with $duration in mIRC scripting. hehe.

        -Khai.
        "Gerard Matthew" <calibishie@gma il.com> wrote in message
        news:1132238149 .775384.271400@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > Thanks
        >[/color]


        Comment

        Working...