我想在不使用数据库的情况下用laravel格式做一个简单的if with语句。我想让表格能让我选择约翰、杰克或詹姆斯。有谁能帮我演示一下如何对表格进行编码?
//I want to make a form in here
@if($name == 'John')
<h2 class="pt-2 tm-color-primary tm-post-tittle">Hai {{$name}}!</h2>
@elseif($name == 'Jack')
<h2 class="pt-2 tm-color-primary tm-post-tittle">Hai {{$name}}!</h2>
@elseif($name == 'James')
<h2 class="pt-2 tm-color-primary tm-post-tittle">Hai {{$name}}!</h2>
@else
<h2 class="pt-2 tm-color-primary tm-post-tittle">I dont know you</h2>
@endif发布于 2022-03-21 15:02:44
您可以创建一个数组并检查$name是否为in_array()。
$checkNames = ['John', 'Jack', 'James'];
@if(in_array($name, $checkNames))
<h2 class="pt-2 tm-color-primary tm-post-tittle">Hai {{$name}}!</h2>
@else
<h2 class="pt-2 tm-color-primary tm-post-tittle">I dont know you</h2>
@endif发布于 2022-03-22 07:53:59
然后,您必须创建您的“伪存储”。在数组中,可以存储所有可用的名称。然后,如果名称位于“伪存储”/数组中,则可以签入if条件。isset()返回true or false。
$names = ['John', 'Jack', 'James'];
$name = 'Jack';
@if(isset($names[$name]))
<h2 class="pt-2 tm-color-primary tm-post-tittle">Hai {{$name}}!</h2>
@else
<h2 class="pt-2 tm-color-primary tm-post-tittle">I dont know you</h2>
@endifhttps://stackoverflow.com/questions/71558650
复制相似问题