How to remove null value from a foreach or array

0

I'm doing a query on a table that has a blank value (student: note). In a page I do the function with select and set the array on a return to call on another page, but I can not delete the blank value to print only those that have data.

$valor = dados_aluno($mysqli);

foreach($valor as $resultado) {

$nome_aluno        = $resultado[1];
$nota              = $resultado[2];

}
    
asked by anonymous 14.06.2018 / 15:55

2 answers

2

If you use continue after verifying that $resultado[2] is null it will move on to the next element without executing the code it is after.

foreach($valor as $resultado) {
    $nome_aluno = $resultado[1];
    $nota       = $resultado[2];

    if (empty($nota)) {
        continue;
    }
}

I changed the is_null to be empty , since the $nota is white and not null.

    
14.06.2018 / 16:01
0

In my application the friend example worked without the keys. I changed the if as well.

$valor = dados_aluno($mysqli);

foreach($valor as $resultado) {
$nome_aluno = $resultado[1];
$nota       = $resultado[2];

if ($nota == "") 
    continue;

}  
    
14.06.2018 / 16:41