Bird
0
0

Which of the following is the correct syntax to start a Blade loop over an array $items?

easy📝 Syntax Q12 of 15
Laravel - Views and Blade Templates
Which of the following is the correct syntax to start a Blade loop over an array $items?
A<code>@loop($items as $item)</code>
B<code>@for($items as $item)</code>
C<code>@while($items as $item)</code>
D<code>@foreach($items as $item)</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Blade loop directives

    Blade uses @foreach to loop over arrays or collections.
  2. Step 2: Match correct syntax

    The correct syntax is @foreach($items as $item), which loops through each item.
  3. Final Answer:

    @foreach($items as $item) -> Option D
  4. Quick Check:

    Loop over array = @foreach [OK]
Quick Trick: Use @foreach for looping arrays in Blade [OK]
Common Mistakes:
  • Using @loop which does not exist
  • Using @for incorrectly for arrays
  • Using @while for array loops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Laravel Quizzes