Luke Skywalker
Luke Skywalker

Reputation: 13

Is there a more concise way of writing this simple PHP conditional?

It seems like there would be a shorter way of writing this:

if ($action == 'add' || $action == 'update' || $action == 'delete') {
       // whatever
}

is there?

Upvotes: 1

Views: 58

Answers (2)

Fabian Iwand
Fabian Iwand

Reputation: 275

I prefer this form, since it is easier to maintain:

if(in_array($action, array('add', 'update', 'delete'))) {

}

Upvotes: 1

El Yobo
El Yobo

Reputation: 14946

if (in_array($action, array('add', 'update', 'delete'))) {
    // whatever
}

Upvotes: 4

Related Questions