[英]PHP: If empty 2 variables for Drupal
I am working in a Drupal template. 我正在使用Drupal模板。 I want to know if two variables exist, and if they do not then do or show something else.
我想知道是否存在两个变量,如果它们不存在,则执行其他操作或显示其他内容。 I know how to do this for only one variable, but what is the correct syntax to look for two?
我知道如何仅对一个变量执行此操作,但是寻找两个变量的正确语法是什么? My code is below.
我的代码如下。
<?php if (!empty($right) && !empty($left)): ?>
<div id="content-main">
<?php endif; ?>
I also tried it this way. 我也尝试过这种方式。
<?php if (!empty($right)&&($left)): ?>
<div id="content-main">
<?php endif; ?>
and this way. 和这种方式。
<?php if (!isset($right)&&($left)): ?>
<div id="content-main">
<?php endif; ?>
None of them work, how do I fix this? 它们都不起作用,我该如何解决?
empty() doesn't check variable initialization, it only checks if it contains a defined set of values that are considered empty ( "", 0, for example). empty()不检查变量的初始化,它仅检查它是否包含定义为空的值(例如““,0)。
Your third example is in the right direction, but needs a small tweak: 您的第三个示例是正确的方向,但需要进行一些细微调整:
<?php if (!isset($right)&&!isset($left)): ?>
<div id="content-main">
<?php endif; ?>
The second conditional check after && requires its own isset() as well. &&之后的第二个条件检查也需要它自己的isset()。
hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.