作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有办法执行以下操作,但简而言之 if/then 语法:
if($method->isAbstract()) {
$details['abstract'] = true;
}
如果我这样做:
$details['abstract'] = $method->isAbstract() ? true : null;
不太一样,因为数组键abstract
总是被设置的。如果 isAbstract()
为真,我只会设置数组键。澄清一下,如果 isAbstract() 为 false,则不要在数组中设置键。
谢谢。
最佳答案
我手边没有 PHP 解释器,但我想这会起作用:
$method->isAbstract() && $details['abstract'] = true;
更新:是的,它有效 → http://codepad.org/lW23FR0j
关于PHP 简写 If Else,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10079806/
我是一名优秀的程序员,十分优秀!