brewpixels brewpixels - 1 year ago 92
PHP Question

Are empty curly brackets, in if statements ok?

This code works for what I want, but I'm wondering if it's ok to do nothing inside the curly brackets of an if statement. Is there a better way to write this?

if(empty($data) || $data == "unanswered")) {
//do nothing
} else {
//display data
echo $data;

Answer Source

You could do a negation instead:

if(!empty($data) && $data != 'unanswered')
    echo $data;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download