Hi,
I've spent two days working on this problem and this forum is my last hope!

Basically, I'm using array_intersect to compare values from two or more different arrays. The array intersect function is meant to return the values that matched from the different arrays.

The database that I'm constructing is on the theme of cars and the arrays have names like "arrayspeed", "arrayenginesize", "arrayyear", "arrayacceleration" and so on.

The particular arrays that I want to intersect will be decided by the results of a search form that the user has submitted.

This means, that neither I, nor PHP have any way of predicting what arrays will need to be intersected.

I have attempted lots of different ways to dynamically generate the array_intersect command, but have had no luck so far.

Can anyone PLEASE help???? This is killing me!

    if you're using a database you can probly do this much more easily in sql.

      10 months later

      What is returned if no intersection is found?

      False? NULL?

      Thanks,
      Bryan

        If nothing intersects, then an empty array is returned. If you did this:

        $array1 = array("red", "green", "yellow");
        $array2 = array("green1", "blue", "black");
        $result = array_intersect($array1, $array2);
        print_r($result);
        

        Your output would be:
        Array() (which indicates it is an empty array)

        But, if you did this:

        $array1 = array("red", "green", "yellow");
        $array2 = array("green", "blue", "black");
        $result = array_intersect($array1, $array2);
        print_r($result);
        

        Your output would be:
        Array ( [1] => green ) (since "green" intersects in the arrays)

        The returned index is [1] because it is the [1] index in the first array ($array1)
        And P.S. Post some of your code so we can actually help you with your example instead of just throwing out generic code...

          Write a Reply...