brewpixels brewpixels - 2 months ago 7
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;


You could do a negation instead:

if(!empty($data) && $data != 'unanswered')
    echo $data;