【发布时间】:2013-10-16 12:28:21
【问题描述】:
简单的东西,
这没有任何问题:
$openMonday = rtrim(chunk_split($result['opening_hours']['periods'][1]['open']['time'], 2, ':'), ':');
$business->openingTimes['monday'] = isset($openMonday) ? $result['opening_hours']['periods'][1]['open']['time'] : '';
但我不想为此写两行,因为那样我就必须在所有其他营业时间都这样做。
为什么我不能写
$business->openingTimes['monday'] = isset(rtrim(chunk_split($result['opening_hours']['periods'][1]['open']['time'], 2, ':'), ':')) ? $result['opening_hours']['periods'][1]['open']['time'] : '';
我总是收到期望变量的错误。如何通过三元运算符使用 isset 中的方法?
【问题讨论】:
-
如果您需要在所有其他营业时间都这样做,您应该尝试使用它!这样就可以写成两行了,调用的时候更简洁。
标签: php function ternary-operator