Doubt request blank webservice PHP

0

Hello,

I have a problem with a part of the code:

function obterBD($nome){

// Conecatar banco de dados
if(!$conn = connectBD()){
    return false;
}

// Incluir/Atualizar retorno no banco de dados
$arrayReturn = getnota($conn, $nome);

if(isset($arrayReturn['registros'])){
    return $arrayReturn;
}

$arrayReturn = array_merge(getmatricula($conn, $nome), $arrayReturn);

$arrayReturn = array_merge(getnomecompleto($conn, $nome), $arrayReturn);

// Encerra conexão com banco
closeBD($conn);

return $arrayReturn;

}

The page is as follows:

Make a request in a webservice and get the data. It turns out that sometimes the "fullname" does not exist and then an error is displayed:

Warning: array_merge(): Argument #1 is not an array in path on line 69 
$arrayReturn = array_merge(getnomecompleto($conn, $nome), $arrayReturn); --> Essa é a linha 69.

And if I comment on this line the error disappears. How do I put it so that if I can not get the full name, write something like: "Not available"?

    
asked by anonymous 06.06.2017 / 14:37

1 answer

1

Validate the returned value before calling array_merge as in the example below. Or follow @Everson's orientation to change the getnomecomplete () function and return an empty array or an array with a 'Not available' item.

$nome_completo = getnomecompleto($conn, $nome);
$nome_completo = is_array($nome_completo) ? $nome_completo : array('Não disponível');
$arrayReturn = array_merge($nome_completo, $arrayReturn);
    
06.06.2017 / 16:35