donh61500 2014-05-14 12:16
浏览 68
已采纳

如果两个php变量中的任何一个不为空,则输出内容。 在本地工作,但不在实时服务器上?

I'm trying to check whether either of two variables are empty, and if either have content, then to output some html.

I'm using WordPress, and each variable is set to use a my_meta function which just gets the content of a meta box from the database. If both functions are empty, no code is output, but if either have content, then the code in the if statement is output.

<?php

$meta_1 = my_meta( 'metabox1' );
$meta_2 = my_meta( 'metabox2' );

if (!empty($meta_1 | $meta_2)) { ?>
    <div>
        <?php echo my_meta( 'metabox1' ); ?>
    </div>
    <div>
        <?php echo my_meta( 'metabox1' ); ?>
    </div>
<?php }

?>

Everything works fine on my local server using MAMP, but when I try the site on a live server, I get the following error.

Parse error: syntax error, unexpected '|', expecting ')'...

Is the code poorly written, or have I missed something?

  • 写回答

1条回答 默认 最新

  • doucheng5209 2014-05-14 12:19
    关注

    just change it to

    if (!empty($meta_1) || !empty($meta_2)) {
    

    it might be due to php versions or different return values form $meta_1 and $meta_2 between prod and localhost

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)