$detect = new Mobile_Detect();
$mobile = $detect->isMobile() and !$detect->isTablet();
VS为什么括号需要
$detect = new Mobile_Detect();
$mobile = ($detect->isMobile() and !$detect->isTablet());
如果我是一个平板电脑(这也被认为是手机),1号例如我的移动越来越真实。 (不期望)。对于第二个例子,我得到了错误(如预期的那样)。
为什么我需要括号,因为它只是一个操作符。
'和'的优先级低于'=',我建议避免它,因为它不像'&&'那样直观' – Esailija
'='具有比'和'更高的优先级。你确定你不是指'&&'而是? –