Zero hide in php

There are two ways to solve my problem : printf("<td>%s</td>", $value != 0 ? $value : '');which avoid number formatting, or $value != 0 ? printf("<td>%d</td>", $value) : printf("<td></td>"); which is longer but more precise.

Try this

printf("<td>%d</td>", $value != 0 ? $value : '');

If you also need to catch empty strings, you can use the following code

printf("<td>%d</td>", $value != 0 && $value != '' ? $value : '');

Leave a Reply

Your email address will not be published. Required fields are marked *