Лучший способ написания заявления If else

Есть ли лучший способ написать это:

if (in_array('WIN_WAITING', $statuses)) {
$this->globalStatus = 'WIN_WAITING';
} else if (in_array('IN_PLAY', $statuses)) {
$this->globalStatus = 'IN_PLAY';
} else if (in_array('WON', $statuses)) {
$this->pay($this->tickets['ticketID']);
$this->globalStatus = 'WON';
} else if (in_array('PAYEDOUT', $statuses)) {
$this->globalStatus = 'PAYEDOUT';
} else if (in_array('CLOSED', $statuses)) {
$this->globalStatus = 'CLOSED';
} else if (in_array('LOST', $statuses)) {
$this->globalStatus = 'LOST';
} else if (in_array('OPEN', $statuses)) {
$this->globalStatus = 'OPEN';
}

1

Решение

Это должно работать для вас:

(Здесь я просто перебираю все ваши строки поиска и, если я нашел его, я разрываю цикл)

<?php

$search = ["WIN_WAITING", "IN_PLAY", "WON", "PAYEDOUT", "CLOSED", "LOST", "OPEN"];

foreach($search as $v) {
if(in_array($v, $statuses)) {
if($v == "WON") $this->pay($this->tickets['ticketID']);
$this->globalStatus = $v;
break;
}

}

?>
3

Другие решения

Может быть что-то вроде

$options = array('WIN_WAITING', 'IN_PLAY', 'WON', 'PAYEDOUT', 'CLOSED', 'LOST', 'OPEN');

for($i=0; $i<=7; $i++) {

if(in_array($options[$i], $statuses)) {
$this->globalStatus = $options[$i];
break;
}

}

Не проверено, просто идея

2