How to use two arrays to make an appointment in the bank?

2

I'm using the Google API, Cloud Vision , to parse an image and return through the Labels, which make / model a car, for example.

Using the image below, I have the following return: [ 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 ]

I first use the returned labels to find out which Brand, in this example would be 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, but now looking for the models, in this example, would have the X3 and X6 models.

Doing so with two arrays.

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

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

My first question is, how do I get these arrays and pass them as a parameter to the Model, returning the search result in the view?

Second question, how to handle cases where one or both of the arrays are null (if API return does not bring a brand name or model).

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

Image used, a BMW X6

    
asked by anonymous 16.01.2018 / 13:53

0 answers