有没有更好的(即更可读)的方式来写这个?
if (isset($input_vars['directive']) && $input_vars['directive'] == 'edit') {
Run Code Online (Sandbox Code Playgroud)
不幸的是,并非如此.您可以将此代码包装在一个函数中,并在每次需要时调用它.
function compareArrayItem($array, $key, $value) {
return isset($array[$key]) && $array[$key] == $value;
}
if (compareArrayItem($input_vars, 'directive', 'edit')) {
// Do something
}
Run Code Online (Sandbox Code Playgroud)
但这对我来说似乎毫无意义(并且比原始代码的可读性差).或者您可以将错误报告级别降低到不包括,E_NOTICE以便您根本不需要第一个表达式.
error_reporting(E_ALL ^ E_NOTICE);
if ($input_vars['directive'] == 'edit') //...
Run Code Online (Sandbox Code Playgroud)
但我不建议这样做只是为了缩短您的代码.
如果我是你,我就不管它了.这很好.
| 归档时间: |
|
| 查看次数: |
290 次 |
| 最近记录: |