douteng5673 2019-07-03 10:45
浏览 142
已采纳

如果echo为空则不显示任何内容

I've got a var that is either empty or not and I want to display nothing when its empty. Code Snippet:

<?php 
 global $bp;
 $user_id = $bp->displayed_user->id; 
 $user_info2 = get_userdata($user_id); 
?>              

<div class="meta">
 <?php _e('Status','fisa'); ?>: <?php echo fidsa_fpsa_status($user_id); ?>
</div>

If The var is empty it still shows Status: is there someway to change this to not output Status: when the var is empty?

  • 写回答

1条回答 默认 最新

  • duanbinian2243 2019-07-03 10:47
    关注

    Assign fidsa_fpsa_status($user_id) to a variable, check if the variable is empty - if its not, print the content!

    <?php 
    global $bp;
    $user_id = $bp->displayed_user->id; 
    $user_info2 = get_userdata($user_id); 
    $fidsa_fpsa_status = fidsa_fpsa_status($user_id);
    
     if (!empty($fidsa_fpsa_status)) {
        ?> 
         <div class="meta">
             <?php _e('Status','fisa'); ?>: <?php echo $fidsa_fpsa_status; ?>
        </div>
        <?php 
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效