momori14 momori14 -4 years ago 91
PHP Question

Proper way for if and else if conditional statement using same function

I got the following PHP code:

if ($_POST['type'] == 'A') {
callfunction();
} elseif ($_POST['type'] == 'B'){
callfunction();
}


both condition calls the same function callfunction(); is there any proper way to do this? Or shoul my logic be okay?

Answer Source

Use the OR operator ||

if ($_POST['type'] == 'A' || $_POST['type'] == 'B') {
   callfunction();
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download