Search for data from an array in a PHP array

0

My problem is as follows, for example, I have a matrix:

ID - Name - Type
152 - item1 - type1
536 - element2 - type2
85 - element3 - type3
105 - item4 - type4

And I have a array :

$busca = array(105,536,85);

What I need is to find the elements of array in the first column of the matrix. I tried going through the matrix and comparing with the elements of the array , the problem is that as the elements are disordered, only results in some, not all.

Any advice? Thank you!

    
asked by Alf 18.05.2018 в 07:15
source

1 answer

3

Suppose your table is called $ array_one, so you can do something like:

        $busca = array(105,536,85);
        $encontrados = [];
        foreach ($array_uno as $item) {
            if (in_array($item->ID, $busca)) {
                array_push($encontrados, $item)
            }
        }
       // Mostrar resultado.
       var_dump($encontrados);

$ encountered will save only the records that have ID in $ search.

    
answered by 18.05.2018 / 07:37
source