PHP does not print result when equal to 0

0

All results are printed on the screen except when it is 0 and I need the 0 number to be printed. If it is NULL it satisfies the condition below and correctly prints the hyphen.

if($dados['dado_1']===null){
  echo "<td width='11%' style='text-align:center;'><p><br/>-</p></td>";
}else{
  echo "<td width='11%' style='text-align:center;><p><br/>".$dados['dado_1']."</p></td>";
}
    
asked by anonymous 22.12.2016 / 14:05

2 answers

2

The correct thing to do is to use is_null , because when the value of the variable is 0 it will return false , so it will not fall into the first IF . My code suggestion:

if(is_null($dados['dado_1'])){
  echo "<td width='11%' style='text-align:center;'><p><br/>-</p></td>";
}else{
  echo "<td width='11%' style='text-align:center;><p><br/>".(string)$dados['dado_1']."</p></td>";
}
    
22.12.2016 / 14:16
1

It should be coming empty, put it like this:

echo "<td width='11%' style='text-align:center;><p><br/>". $dados['dado_1'] ? $dados['dado_1'] : '0' ."</p></td>";
    
22.12.2016 / 14:07