[英]PHP echo with three levels of nested quotes
我想執行以下回聲:
echo '<div class="grid grid-cols-1 mt-4">
@foreach( $sectionOneCompare as $chart )
<livewire:is :component="$chart['type']">
@endforeach
</div>'
你會注意到引用嵌套的三個層次......這就是讓我難過的地方。 已經有一百萬個問題被問到了,他們都說要像這樣逃跑:
echo "<div class=\"grid grid-cols-1 mt-4\">
@foreach( $sectionOneCompare as $chart )
<livewire:is :component=\"$chart['type']\">
@endforeach
</div>"
...但它對我不起作用。 兩種方式,它都無法正確解析。 如何正確嵌套?
編輯:我忽略了我原來的問題,即這個回聲在 PHP if 語句中:
<?php if ($sectionOne != null) {
// above code snippet
} ?>
由於我使用的是 Blade/Livewire,答案最終是使用 Blade 條件代替。 這樣我就不用嵌套引號了。 感謝 Qirel 的評論幫助我實現了這一點。
@if ($sectionOne != null)
// above code snippet
@endif
我不知道livewire,但我認為你想要的是這個
echo '<div class="grid grid-cols-1 mt-4">';
@foreach( $sectionOneCompare as $chart )
<livewire:is :component="$chart['type']">
@endforeach
echo '</div>';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.