当使用带有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

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