Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are empty curly brackets, in if statements ok? [closed]

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;
}
like image 443
brewpixels Avatar asked Nov 30 '22 23:11

brewpixels


1 Answers

You could do a negation instead:

if (! empty($data) && $data != 'unanswered') {
    echo $data;
}
like image 81
Chin Leung Avatar answered Dec 16 '22 10:12

Chin Leung