这在 Drupal 中,但应该适用于普通 PHP。
field-event-address 是一个位于$entity_fetched
.
<?php if ($entity_fetched->field-event-address != "") echo $entity_fetched->field-event-address['und']['0']['value']; ?>
出于某种原因,当我这样做时,如果我关闭,我会收到此错误['und']['0']['value']
:
Notice: Undefined property: stdClass::$field in eval() (line 7 of /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code).
Notice: Use of undefined constant event - assumed 'event' in eval() (line 7 of /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code).
Notice: Use of undefined constant address - assumed 'address' in eval() (line 7 of /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code).
如果我把它留在上面,这个错误:
Parse error: syntax error, unexpected '[', expecting ',' or ';' in /opt/staging/contitemp/public_html/sites/all/modules/rules/modules/php.eval.inc(125) : eval()'d code on line 7
我正在尝试创建一个 if 语句来检查对象下的数组是否为空,如果不是,则回显数组内容。
我真的对这个摸不着头脑-如果数组在对象下,我应该能够检查它是否为空,对吗?