Edned Edned - 1 year ago 106
PHP Question

If Statement (Do Nothing)

this question is really about bad practice when it comes to PHP. I'm learning how to code in this language and I can already code in Lua & Python. When an if statement is told to "do nothing" in Lua, you would literally just say "return", but I understand that doesn't work in PHP. I've been using print() instead, but I understand that's probably bad practice and I was wondering if there was a function for doing nothing.

if (condition) { //If condition is met
print(""); //Do Nothing
} else {
//Run the function;

Thank you in advance.

Answer Source

the easiest way would be:

if(condition) {

} else {
    // your code

the smart and clean way, however, would be to negate your condition:

if(!condition) {
    // your code

and be done with it.


if your condition is complex, don't forget to use parentheses:

if(!(condition_A && condition_B)) {
    //your code
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download