How to remove null value from a foreach or array

Asked

Viewed 279 times

0

I am making a query in a table that has a blank value(student:note). On one page I do the function with select and play the array on a Return to call on another page, but I can’t delete the blank value to print only those that have dice.

$valor = dados_aluno($mysqli);

foreach($valor as $resultado) {

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

}

2 answers

3

If you use the continue after verifying that the $resultado[2] is null it will pass to the next element without executing the code that 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.

  • Unfortunately it didn’t work here, it didn’t print anything, nor the positives are printing.

  • $nota is always null, or before showed something? Gave some error or the page is working normally, but no longer only show the results?

  • I took the keys and it worked. thank you very much for the collaboration

  • 1

    use Empty!!!

  • 1

    I must have been changing it when you wrote the comment :)

0

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

$valor = dados_aluno($mysqli);

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

if ($nota == "") 
    continue;

}  

Browser other questions tagged

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