I am consuming a Web Service for the first time, I created a function to go through the columns of a variable, find the value I need, using array_search to find another value in a different variable and replace the names the big problem is that sometimes when reloading the page it returns me errors on several lines, sometimes in the array_column other in array_search or foreach :
array_column () expects parameter 1 to be array, null given in
on line:
$loc = array_column($local, 'codigo');
array_search () expects parameter 2 to be array, null given in
in the lines:
$cat = array_column($categoria, 'codigo');
$categorizacao = $categoria[$key4]['nome'];
$key3 = array_search($result['local'], $loc);
and returned the error:
Invalid argument supplied for foreach () in
on line:
foreach($resultado as $result){
I tried adding multiple lines with is_array, but that's certainly not right, and the error still happens, I'd like to know if I can add more than one variable in is_array, to use only one, or a correct way to apply in my code, I'm a beginner in php, I count on your help!
$retorno_resultados = array();
$colunas = array_column($equipe, 'codigo');
$loc = array_column($local, 'codigo');
$cat = array_column($categoria, 'codigo');
foreach((array)$modalidade as $modali){
if(!is_array($modali)){
}else{
$mod = array_column($modalidade, 'codigo');
}
}
foreach((array)$campeonato as $camp){
if(!is_array($camp)){
}else{
$key4 = array_search($camp['categoria'], $cat);
$categorizacao = $categoria[$key4]['nome']; // <-- pega o valor
$key5 = array_search($camp['modalidade'], $mod);
$modalidadez = $modalidade[$key5]['nome']; // <-- pega o valor
foreach((array)$resultado as $result){
if(!is_array($result)){
}else{
// pesquisa chave do mandante
$key1 = array_search($result['mandante'], $colunas);
$mandante = $equipe[$key1]['nome']; // <-- pega o valor
// pesquisa chave do visitante
$key2 = array_search($result['visitante'], $colunas);
$visitante = $equipe[$key2]['nome']; // <-- pega o valor
// pesquisa chave do local
$key3 = array_search($result['local'], $loc);
$localizacao = $local[$key3]['nome']; // <-- pega o valor
$data = $result['data'];
$data = date('d/m/Y', strtotime($data));
$i = 0;
$ columns
{
"codigo": "26",
"nome": "Xingu SA",
"nomeabreviado": "XINGU",
"url": "xingu-sa",
"telefone": "",
"email": "",
"endereco": "",
"complemento": null,
"bairro": "",
"cidade": "",
"uf": "",
"cep": ""
},
"Total de registros: 36"
],
$ mod
{
"codigo": "256",
"nome": "Xadrez",
"tipo": "6"
},
"Total de registros: 47"
],
$ loc
{
"codigo": "17",
"nome": "Villare SCS",
"modalidade": "16",
"telefone": "",
"email": "",
"endereco": "",
"complemento": null,
"bairro": "",
"cidade": "",
"uf": "",
"cep": ""
},
"Total de registros: 21"
],
$ cat
{
"codigo": "36",
"nome": "Sub 10",
"ordem": "340"
},
"Total de registros: 36"
],