dongling0519 2018-09-26 03:09
浏览 52
已采纳

当使用带有OR的多变量时,PHP是否无效

I have laravel blade template that use if else to show the alert.

here my code

@if($foo = Request('foo') and ($bar = Request('bar')))
    Search result for: <strong>{{ $foo }} and {{ $bar }}
@endif

on my code above

it's working if both forms filled. but when one of them form empty its print nothing.

how to make it if one or both filled its return like :

one form filled.

Search result for: Keyword

both form filled.

Search result for: Keyword and category
  • 写回答

1条回答 默认 最新

  • douyou2234 2018-09-26 03:17
    关注

    The problem is that you are using and to denote that both fields must be entered. While just an or could suffice, this will have the problem that the extra field will be outputted. To correct this, you'll want independent outputs for when either field is entered, outputting the relevant field. Then you'll want another output for when both fields are entered.

    If you have the condition for both fields as the main @if conditional, it won't be entered into when only field is set, so you can use @elseif for the other two outputs:

    @if($foo = Request('foo') and ($bar = Request('bar')))
        Search result for: <strong>{{ $foo }} and {{ $bar }}
    @endif
    
    @elseif($foo = Request('foo'))
        Search result for: <strong>{{ $foo }}
    @endif
    
    @elseif($bar = Request('bar'))
        Search result for: <strong>{{ $bar }}
    @endif
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?