是否有快捷方式来打开fn(case_value)的结果


Is there a shortcut to switch on result of fn(case_value)?

switch (true) {
    case array_key_exists('view', $load):
        # code...
        break;
    case array_key_exists('model', $load):
        # code...
        break;
    default:
        # code...
        break;
}

这个代码工作得很好。但这很费力。什么是捷径?这样的

switch ($a = array_key_exists($a, $load)) {
    case 'view':
        # code...
        break;
    case 'model':
        # code...
        break;
    default:
        # code...
        break;
}

但是不行

在PHP中没有这种操作的快捷方式。

然而,原始代码应该可能写成
if (array_key_exists('view', $load)) {
    // ..
} else if (array_key_exists('model', $load)) {
    // ..
} else {
    // ..
}
#check if exists
if(array_key_exists($a, $load))  
#check what exists
switch ($a) {
    case 'view':
        # code...
        break;
    case 'model':
        # code...
        break;
    default:
        # code...
        break;
}
#case for nothing matched
else{
  # code...
}