Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel,如果条件满足,如何更改文本?_Php_Laravel_Laravel 5.4 - Fatal编程技术网

Php Laravel,如果条件满足,如何更改文本?

Php Laravel,如果条件满足,如何更改文本?,php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,目前这是我认为的代码 在视图中 <?php $cond = true ?> <p id="p1">I wanted to change this text if the condition is met</p> @if($cond) //what should i do here to change the text above? @endif 如果满足条件,我想更改此文本 @如果($cond) //我应该在这里做什么来更改上面的文本? @恩迪夫

目前这是我认为的代码

在视图中

<?php $cond = true ?>

<p id="p1">I wanted to change this text if the condition is met</p>
@if($cond)
  //what should i do here to change the text above?
@endif

如果满足条件,我想更改此文本

@如果($cond) //我应该在这里做什么来更改上面的文本? @恩迪夫

把它改成html怎么样?像这样

$text = "<i class='fa fa-times' style='color: red'></i>";
$text=”“;

您可以将该文本放入某个变量中,如果条件为true,您可以只更新变量的值。 假设你有一个变量

$someText = "I wanted to change this text if the condition is met";
这就是你的观点:

<?php $cond = true ?>

@if($cond)
  <?php $someText = "Now I have new text"; ?>
@endif

<p id="p1">{{$someText}}</p>

您可以将该文本放入某个变量中,在condition=true时,您可以只更新变量的值。 假设你有一个变量

$someText = "I wanted to change this text if the condition is met";
这就是你的观点:

<?php $cond = true ?>

@if($cond)
  <?php $someText = "Now I have new text"; ?>
@endif

<p id="p1">{{$someText}}</p>

也许这个问题很简单

<p id="p1">{!! $con ? "I wanted to change this text if the condition is met" : "<i class='fa fa-times' style='color: red'></i>" !!}</p>

{!!$con?”如果满足条件,我想更改此文本:“!!”


也许这个问题很简单

<p id="p1">{!! $con ? "I wanted to change this text if the condition is met" : "<i class='fa fa-times' style='color: red'></i>" !!}</p>

{!!$con?”如果满足条件,我想更改此文本:“!!”


还有其他更简单的方法吗?也许需要更少的内存?把它改成html怎么样?像这个$text=“”;我认为它更简单,只需要一个变量来存储文本。你认为这会花费昂贵的内存调用费用吗?或者,如果你不想使用temp变量,那么你只需在条件中更新,并在if-else两个块中显示文本。听起来不错,顺便问一下,我更新了我的问题…你有什么想法来解决这个问题吗?欢迎,很高兴它有帮助。还有其他更简单的方法吗?也许需要更少的内存?把它改成html怎么样?像这个$text=“”;我认为它更简单,只需要一个变量来存储文本。你认为这会花费昂贵的内存调用费用吗?或者,如果你不想使用temp变量,那么你可以简单地在条件中更新,并在if-else两个块中显示文本。听起来不错,顺便说一下,我更新了我的问题…你有什么解决问题的办法吗?欢迎,很高兴它有帮助。