遵循规则 - “if”语句需要调用一个函数而不是一个函数 - 我选择了三种方法

How to write code without if body and call a function instead for better readability. Each approach as I think has disadvantages 1. Unnecessary else word. I can complete this without else 2. A ternary operator used for returning value. It seems clean, but is it right using ternary operator without returning value? 3. Every time I need to repeat the keyword return. Seems not so clean; Unlike the 1. approach this approach has only 1 branch. And calling b() seems clean, unlike the 1 approach.

I'm stucking with this. I want to write clean code but I don`t know what to choose. Maybe do you know a better way than these 3 approaches? Or can you argue wich approach in what situation to use?

1.

 if ($contidition) {
        a();
    } else {
        b();
    }

2.

$contidition ? a() : b();

3.

if ($contidition) {
    a();
    return;
}

b();

I don't understand your question. If you want to put something in the if statement but not in the else statement you can just say:

if a != b {print(a)} 

You don't have to write else.