Doubt blank PHP webservice request

Asked

Viewed 25 times

0

Hello,

I’m having a problem with one 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 on a webservice and take the data. It turns out that sometimes there is no "full name" and then error is shown:

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 this line the error disappears. As I put so that if you can’t get the full name, write something like: "Not available" ?

  • In function getnomecompleto return an empty array or an array with the empty position.

  • @Everson, an empty array.

1 answer

2


Validate the returned value before calling the merge array_as in the example below. Or follow @Everson’s guidance to change the full getname() function and return an empty array or array with an '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);

Browser other questions tagged

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