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 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳