How to use two arrays to make a query in the bank?

Asked

Viewed 39 times

2

I’m using the Google API, the Cloud Vision, to analyze an image and return me through the labels, which brand/model of a car, for example.

Using the image below, I have the following feedback: [car, land vehicle, vehicle, motor vehicle, bmw, personal luxury car, bmw x6, sport utility vehicle, luxury vehicle, mid size car, automotive design, crossover suv, bmw concept x6 activehybrid, vehicle registration plate, bumper, family car, automotive exterior, executive car, compact car, bmw x3]

First I use the returned Abels to search for the Brand, in this example BMW.

$marcaUnica = []; // Array para comparação de labels, evitando nomes duplicados.
    foreach ($nomes as $nome) { // Percorrendo todas as labels retornadas.
        $partes = explode(" ", $nome); // Separando nomes composto. EX: bmw x6
        foreach ($partes as $parte){ // Percorrendo as labels separadas.
            if(in_array($parte, $marcaUnica)){ // Verificando se a label existe no Array.
                      /* Caso exista não faz nada */
            }else{
                $marcaUnica[] = $parte; // Se não existir adiciona
                $retornoMarca[] = $this->m_consulta->marca($parte); //Faz uma busca no banco de dados com todas as labels, retornando apenas a label que existir no banco cadastrada como uma marca de carro. Nesse exemplo a unica marca e BMW.
            }
        }

    }

Then I make the same query, only now searching for the models, in this example, would have the models X3 and X6.

Getting like this with two arrays.

array(1) { [0]=> string(3) "BMW" }

array(2) { [0]=> string(2) "X3" [1]=> string(2) "X6" }

My first question is, how to take these arrays and pass as parameter to the Model, returning the result of the search in the view?

Second doubt, how to deal with cases where one or both arrays is null (in case the return of the API does not carry brand name or model).

I hope my doubt has been made clear, any doubt in the code just ask me, I thank you for the attention of all.

Used image, a BMW X6

BMW X6

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.