Perform search in an array by parameters

0

I have a function that, according to the parameters, performs a search in an array and returns a number of an account

 public function putAssignamentAccount($Agrupacion, $TipoPersona, $pais, $segmento = null)
{
    $model_get = new $this->modelClass;

    $model = $model_get::find([
        "conditions" => "agrupacion = :Agrupacion: AND tipo_persona = :TipoPersona:",
        "bind"       => ["Agrupacion"=>$Agrupacion, "TipoPersona" => $TipoPersona]
    ])->toArray();

    $data_segmento = array_column($model, "segmento_mercado");
    $_segmento= "";
    if (in_array($segmento == "null",$data_segmento)) {
        $_segmento = "NA";
    } else {
        $_segmento = $data_segmento[array_search($segmento, $data_segmento)];
    }

    $data_pais = array_column($model, "pais");
    $_pais="";

    if (!in_array($pais, $data_pais)) {
        $_pais = 'OTHR';
    } else {
        $_pais=  $data_pais[array_search($pais, $data_pais)];
    }


    $data_cuenta = array_column($model, "grupo_cuentas");
    $cuenta = $data_cuenta[array_search($data_cuenta, $model)];


    if ($model == true) {
        return $this->buildSuccessResponse(200, "SUCCESSFUL REQUEST", [$cuenta]);
    }
    return $this->buildErrorResponse(404, 'Error al relizar la consulta');
}

I send 4 parameters and the search is performed according to the 4 parameters.

But in this case I do not know what I'm doing wrong, since it only searches for the first 2 parameters

    
asked by Luis Enrique Gómez Pérez 27.12.2018 в 15:04
source

0 answers