I want to make a simple if else statement with form in laravel without using a database. I want to make the form can make me choose as John, Jack, or James. Can anyone please help me show how to code the form
//I want to make a form in here
@if($name == 'John')
<h2 >Hai {{$name}}!</h2>
@elseif($name == 'Jack')
<h2 >Hai {{$name}}!</h2>
@elseif($name == 'James')
<h2 >Hai {{$name}}!</h2>
@else
<h2 >I dont know you</h2>
@endif
CodePudding user response:
You can create an array and check if $name
is in_array()
:
$checkNames = ['John', 'Jack', 'James'];
@if(in_array($name, $checkNames))
<h2 >Hai {{$name}}!</h2>
@else
<h2 >I dont know you</h2>
@endif
CodePudding user response:
Then you have to create your "pseudo storage". In an array you can store all available names. Then you can check in your if condition if the name are in your "pseudo storage" / array. isset()
returns true or false
.
$names = ['John', 'Jack', 'James'];
$name = 'Jack';
@if(isset($names[$name]))
<h2 >Hai {{$name}}!</h2>
@else
<h2 >I dont know you</h2>
@endif